Example usage for org.apache.maven.plugin.logging Log warn

List of usage examples for org.apache.maven.plugin.logging Log warn

Introduction

In this page you can find the example usage for org.apache.maven.plugin.logging Log warn.

Prototype

void warn(Throwable error);

Source Link

Document

Send an exception to the user in the warn error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

From source file:de.hwbllmnn.maven.DistMojo.java

License:GNU General Public License

public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    File basedir = project.getBasedir();
    File target = new File(basedir, "target/dist");

    if (!target.isDirectory() && !target.mkdirs()) {
        log.warn("Could not create target directory: " + target);
    }/* w w w .  j a  v  a  2  s  . c om*/

    List<Artifact> artifacts = new LinkedList<Artifact>();
    @SuppressWarnings("unchecked")
    List<Object> modules = project.getCollectedProjects();
    if (includeProjectArtifacts) {
        modules.add(project);
    }
    for (Object o : modules) {
        MavenProject module = (MavenProject) o;
        List<?> arts = module.getAttachedArtifacts();
        for (Object obj : arts) {
            artifacts.add((Artifact) obj);
        }
        if (!includeOnlyAttachedArtifacts) {
            artifacts.add(module.getArtifact());
        }
    }

    log.info("Collected artifacts: " + artifacts);

    for (Artifact a : artifacts) {
        File file = a.getFile();
        if (file == null) {
            log.warn("Skipping non-existing artifact: " + a);
            continue;
        }
        try {
            copyFile(file, new File(target, file.getName()));
            log.info("Copied artifact " + file.getName());
        } catch (IOException e) {
            log.warn("Could not copy artifact: " + file);
        }
    }
}

From source file:de.kaiserpfalzEdv.maven.apacheds.ApacheDsLifecycle.java

License:Apache License

public void stop(final Log logger) throws Exception {
    if (isStarted()) {
        logger.info("Stopping Apache Directory Server ...");

        server.shutdown();/*from  w w  w. j a  va  2 s  .  c o  m*/
    } else {
        logger.warn("No Apache Directory Server to be stopped!");
    }
}

From source file:de.mmichaelis.maven.mojo.mail.MailExpiration.java

License:Apache License

/**
 * Parses the mail expiration argument. If it is an integer it is assumed that the
 * expiration is given in days.//from   ww  w .  ja v  a2  s .  c  om
 *
 * @param arg the expiration argument as number of days; <code>null</code>, negative values, empty string or parsing errors will cause default expiration 1 day; 0 will disable expiration
 * @param log where to write log information to
 * @return the mail expiration
 */
public static MailExpiration parse(final String arg, final Log log) {
    final Calendar calendar = Calendar.getInstance();
    final Date expDate;
    if (isEmpty(arg)) {
        calendar.add(Calendar.DAY_OF_MONTH, DEFAULT_EXPIRATION_DAYS);
        expDate = calendar.getTime();
    } else {
        int parsedInteger;
        try {
            parsedInteger = Integer.parseInt(arg);
            if (parsedInteger < 0) {
                log.warn("Expiration days is negative. Using default value as expiration.");
                parsedInteger = DEFAULT_EXPIRATION_DAYS;
            }
        } catch (NumberFormatException e) {
            log.warn("Expiration argument '" + arg + "' is not a number. Using default value as expiration.");
            parsedInteger = DEFAULT_EXPIRATION_DAYS;
        }
        if (parsedInteger == 0) {
            expDate = null;
        } else {
            calendar.add(Calendar.DAY_OF_MONTH, parsedInteger);
            expDate = calendar.getTime();
        }
    }
    return new MailExpiration(expDate);
}

From source file:de.mmichaelis.maven.mojo.mail.MailPriority.java

License:Apache License

/**
 * Parses the given priority. Argument will be trimmed.
 * @param arg the priority to parse; null and empty string will cause the default value to use.
 * @param log where to log problems to/*  w  w  w  . j  ava  2s.com*/
 * @return the parsed priority; guaranteed to be non-null
 */
public static MailPriority parse(final String arg, final Log log) {
    MailPriority result = null;
    if (isEmpty(arg)) {
        result = LOW;
    } else {
        final MailPriority[] values = MailPriority.values();
        for (final MailPriority prio : values) {
            if (prio.matches(arg)) {
                result = prio;
                break;
            }
        }
        if (result == null) {
            log.warn("Could not parse priority '" + arg + "'. Using default priority.");
            result = LOW;
        }
    }
    return result;
}

From source file:de.mmichaelis.maven.mojo.Message.java

License:Apache License

public String getText(final Log log) throws MojoExecutionException, MojoFailureException {
    if (text == null && textFile == null) {
        throw new MojoExecutionException("You should either specify <text> or <textFile> as message.");
    }/*from ww w .  ja v  a  2s .c o  m*/
    if (text != null && textFile != null) {
        log.warn("Specified both <text> and <textFile> as message. <textFile> will be taken.");
    }
    if (textFile != null) {
        return getPlainTextFromFile(textFile);
    }
    return text;
}

From source file:de.shadowhunt.maven.plugins.packageinfo.PackageInfoPlugin.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();

    if (isEmpty(annotationLines)) {
        log.warn("no annotationLines give: not generating any package-info.java files");
        return;/*from   w  ww.  ja v  a 2s  . co  m*/
    }

    try {
        for (final String compileSourceRoot : compileSourceRoots) {
            final File root = makeFileAbsolute(new File(compileSourceRoot));
            log.debug("checking " + root + " for missing package-info.java files");
            processFolder(root, root);
        }
    } catch (final IOException e) {
        throw new MojoExecutionException("could not generate package-info.java", e);
    }

    final File absoluteOutputDirectory = makeFileAbsolute(outputDirectory);
    final String outputPath = absoluteOutputDirectory.getAbsolutePath();
    if (!project.getCompileSourceRoots().contains(outputPath)) {
        project.addCompileSourceRoot(outputPath);
    }
}

From source file:de.smartics.maven.enforcer.rule.AbstractNoCyclicPackageDependencyRule.java

License:Apache License

/**
 * {@inheritDoc}/*from  w ww .ja  va2 s .  c  o m*/
 */
// CHECKSTYLE:OFF
@SuppressWarnings("unchecked")
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
    final Log log = helper.getLog();

    try {
        final MavenProject project = (MavenProject) helper.evaluate("${project}");
        final String projectName = project.getName();

        final File classesDir = new File((String) helper.evaluate("${project.build.outputDirectory}"));

        if (classesDir.canRead()) {
            final JDepend jdepend = new JDepend();
            jdepend.addDirectory(classesDir.getAbsolutePath());
            addTestClassesIfRequested(helper, classesDir, jdepend);

            final Collection<JavaPackage> packages = jdepend.analyze();
            if (jdepend.containsCycles()) {
                final String buffer = collectCycles(packages);
                throw new EnforcerRuleException(
                        "Dependency cycle check found package cycles in '" + projectName + "': " + buffer);
            } else {
                log.info("No package cycles found in '" + projectName + "'.");
            }
        } else {
            log.warn("Skipping package cycle analysis since '" + classesDir + "' does not exist.");
        }
    } catch (final ExpressionEvaluationException e) {
        throw new EnforcerRuleException(
                "Dependency cycle check is unable to evaluate expression '" + e.getLocalizedMessage() + "'.",
                e);
    } catch (final IOException e) {
        throw new EnforcerRuleException("Dependency cycle check is unable to access a classes directory '"
                + e.getLocalizedMessage() + "'.", e);
    }
}

From source file:de.tarent.maven.plugins.pkg.helper.Helper.java

License:Open Source License

/**
 * Investigates the project's runtime dependencies and prepares them to be
 * copied into the package.//from   ww w .j  a v  a  2 s .c o  m
 * 
 * @param l
 * @param targetJarPath
 * @param bcp
 * @param cp
 * @param targetArtifactFile
 * @return
 * @throws MojoExecutionException
 */
protected final Set<Artifact> bundleDependencies(final Log l, final Set<Artifact> resolvedDependencies,
        final File targetJarPath, final Path bcp, final Path cp, File targetArtifactFile)
        throws MojoExecutionException {

    final Set<Artifact> bundled = new HashSet<Artifact>();

    l.info("Copying dependencies into package");

    Visitor v = new Visitor() {
        public void bundle(Artifact artifact) {
            // Put to artifacts which will be bundled (allows copying and
            // filesize
            // summing later).
            bundled.add(artifact);

            // TODO: Perhaps one want a certain bundled dependency in boot
            // classpath.

            // Bundled Jars will always live in targetJarPath
            File file = artifact.getFile();
            if (file != null) {
                cp.append(targetJarPath.toString() + "/" + file.getName());
            } else {
                l.warn("Cannot bundle artifact " + artifact.getArtifactId());
            }
        }

        public void visit(Artifact artifact, Entry entry) {

            /**
             * Only if we wish to bundle dependency artifacts we will do so
             */
            if (targetConfiguration.isBundleDependencyArtifacts()) {

                // If all dependencies should be bundled take a short-cut to
                // bundle()
                // thereby overriding what was configured through property
                // files.
                if (targetConfiguration.isBundleAll()) {
                    bundle(artifact);
                    return;
                }

                Path b = (entry.isBootClasspath) ? bcp : cp;

                Iterator<String> ite = entry.jarFileNames.iterator();

                while (ite.hasNext()) {
                    StringBuilder sb = new StringBuilder();
                    String fileName = ite.next();

                    // Prepend default Jar path if file is not absolute.
                    if (fileName.charAt(0) != '/') {
                        sb.append(packageMap.getDefaultJarPath());
                        sb.append("/");
                    }

                    sb.append(fileName);

                    b.append(sb.toString());
                }
            }
        }

    };

    packageMap.iterateDependencyArtifacts(l, resolvedDependencies, v, true);

    // Add the custom jar files to the classpath
    for (Iterator<JarFile> ite = targetConfiguration.getJarFiles().iterator(); ite.hasNext();) {
        AuxFile auxFile = ite.next();

        cp.append(targetJarPath.toString() + "/" + new File(auxFile.getFrom()).getName());
    }

    // Add the project's own artifact at last. This way we can
    // save the deletion of the colon added in the loops above.
    cp.append(targetArtifactFile.toString());

    return bundled;
}

From source file:de.tarent.maven.plugins.pkg.map.PackageMap.java

License:Open Source License

public void iterateDependencyArtifacts(Log l, Collection<Artifact> deps, Visitor v, boolean bundleNonExisting) {
    for (Iterator<Artifact> ite = deps.iterator(); ite.hasNext();) {
        Artifact a = ite.next();/*w ww.jav  a2  s . co  m*/
        String aid = a.getArtifactId();

        // Bundle dependencies which have been explicitly
        // marked as such.
        if (bundleOverrides.contains(aid)) {
            v.bundle(a);
            continue;
        }

        Entry e;
        try {
            e = mapping.getEntry(a.getGroupId(), aid, a.getSelectedVersion());
        } catch (OverConstrainedVersionException e1) {
            throw new IllegalStateException("Unable to retrieve selected artifact version.", e1);
        }
        // If a distro is explicitly declared to have no packages everything
        // will be bundled (without warning).
        if (mapping.hasNoPackages) {
            v.bundle(a);
        } else if (e == null) {
            // If a package as not been declared a warning reminds to fix
            // the
            // package map.
            l.warn(mapping.distro + " has no entry for: " + a);

            if (bundleNonExisting) {
                v.bundle(a);
            }
        } else if (e.bundleEntry) {
            // If a package is explicitly said to be bundled this will be
            // done
            // without warning.
            v.bundle(a);
        } else if (e.ignoreEntry) {
            // If a package is explicitly said to be ignored this will be
            // done without warning.
            l.debug("Ignoring entry '" + e.artifactSpec + "', ignoreEntry flag is set");
        } else {
            // Otherwise we have a plain dead easy Entry which needs to be
            // processed
            // somehow.
            v.visit(a, e);
        }
    }
}

From source file:de.tarent.maven.plugins.pkg.packager.IpkPackager.java

License:Open Source License

/**
 * Creates a control file whose dependency line can be provided as an
 * argument./*from w  w  w  .jav a2 s  .  com*/
 * 
 */
private void generateControlFile(Log l, Helper ph, TargetConfiguration dc, File controlFile, String packageName,
        String packageVersion, String dependencyLine, long byteAmount) throws MojoExecutionException {
    ControlFileGenerator cgen = new ControlFileGenerator();
    cgen.setPackageName(packageName);
    cgen.setVersion(packageVersion);
    cgen.setSection(dc.getSection());
    cgen.setDependencies(dependencyLine);
    cgen.setMaintainer(dc.getMaintainer());
    cgen.setArchitecture(dc.getArchitecture());
    cgen.setOE(packageName + "-" + packageVersion);

    String url = ph.getProjectUrl();
    if (url == null) {
        l.warn("Project has no <url> field. However IPK packages require this. Using a dummy for now.");
        url = "http://not-yet-set.org/" + packageName;
    }
    cgen.setSource(url);
    cgen.setHomepage(url);

    String desc = ph.getProjectDescription();
    if (desc == null) {
        l.warn("Project has no <description> field. However IPK packages require this. Using a placeholder for now.");
        desc = "No description given yet.";
    }
    cgen.setShortDescription(desc);

    l.info("creating control file: " + controlFile.getAbsolutePath());
    Utils.createFile(controlFile, "control");

    try {
        cgen.generate(controlFile);
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while creating control file.", ioe);
    }
}