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(CharSequence content, Throwable error);

Source Link

Document

Send a message (and accompanying exception) to the user in the warn error level.
The error's stacktrace will be output when this error level is enabled.

Usage

From source file:org.apache.karaf.tooling.utils.Dependency30Helper.java

License:Apache License

@Override
public File resolveById(String id, Log log) throws MojoFailureException {
    if (id.startsWith("mvn:")) {
        if (id.contains("!")) {
            id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
        }/*from  w ww  .  ja  v  a  2  s .  c  om*/
        if (id.endsWith("/")) {
            id = id.substring(0, id.length() - 1);
        }
    }
    id = MavenUtil.mvnToAether(id);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(id));
    request.setRepositories((List<RemoteRepository>) projectRepositories);

    log.debug("Resolving artifact " + id + " from " + projectRepositories);

    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + id, e);
        throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
    }

    log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}

From source file:org.apache.karaf.tooling.utils.Dependency31Helper.java

License:Apache License

@Override
public File resolveById(String id, Log log) throws MojoFailureException {
    if (id.startsWith("mvn:")) {
        if (id.contains("!")) {
            id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
        }//  w w w .j  a  v  a 2s .c o m
        if (id.endsWith("/")) {
            id = id.substring(0, id.length() - 1);
        }
    }
    id = MavenUtil.mvnToAether(id);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(id));
    request.setRepositories(projectRepositories);

    log.debug("Resolving artifact " + id + " from " + projectRepositories);

    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + id, e);
        throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
    }

    log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from "
            + result.getRepository());

    return result.getArtifact().getFile();
}

From source file:org.codehaus.mojo.apt.LogUtils.java

License:Open Source License

public static void log(Log log, int level, File file, CharSequence prefix) {
    if (!isEnabled(log, level)) {
        return;//from   w w  w  . j av  a  2  s  .  c o m
    }

    FileReader reader = null;

    try {
        reader = new FileReader(file);

        log(log, level, reader, prefix);
    } catch (FileNotFoundException exception) {
        log.warn("Error logging file", exception);
    } finally {
        IOUtil.close(reader);
    }
}

From source file:org.codehaus.mojo.apt.LogUtils.java

License:Open Source License

public static void log(Log log, int level, Reader reader, CharSequence prefix) {
    if (!isEnabled(log, level)) {
        return;/*  w  ww. ja  v  a 2s .  co m*/
    }

    BufferedReader bufferedReader = new BufferedReader(reader);

    String line;

    try {
        while ((line = bufferedReader.readLine()) != null) {
            log(log, level, line, prefix);
        }
    } catch (IOException exception) {
        log.warn("Error logging reader", exception);
    }
}

From source file:org.codehaus.mojo.mrm.impl.maven.MockArtifactStore.java

License:Apache License

/**
 * Create a mock artifact store by scanning for POMs within the specified root.
 *
 * @param root the root to search for POMs within.
 * @param log  the {@link Log} to log to.
 * @since 1.0//from  w  w w.ja  v  a2  s . c o m
 */
public MockArtifactStore(Log log, File root, boolean lazyArchiver) {
    this.log = log;
    this.lazyArchiver = lazyArchiver;

    if (root.isDirectory()) {
        MavenXpp3Reader pomReader = new MavenXpp3Reader();
        Collection<File> poms = FileUtils.listFiles(root, POM_EXTENSIONS, true);
        for (File file : poms) {
            FileReader fileReader;
            try {
                fileReader = new FileReader(file);
                Model model = pomReader.read(fileReader);
                String groupId = model.getGroupId() != null ? model.getGroupId()
                        : model.getParent().getGroupId();
                String version = model.getVersion() != null ? model.getVersion()
                        : model.getParent().getVersion();
                set(new Artifact(groupId, model.getArtifactId(), version, "pom"), new FileContent(file));

                final String basename = FilenameUtils.getBaseName(file.getName());

                if (StringUtils.isEmpty(model.getPackaging()) || "jar".equals(model.getPackaging())) {
                    File mainFile = new File(file.getParentFile(), basename + ".jar");

                    Content content;
                    if (mainFile.isDirectory()) {
                        content = new DirectoryContent(mainFile, lazyArchiver);
                    } else {
                        content = new BytesContent(Utils.newEmptyJarContent());
                    }

                    set(new Artifact(groupId, model.getArtifactId(), version, "jar"), content);
                } else if ("maven-plugin".equals(model.getPackaging())) {
                    set(new Artifact(groupId, model.getArtifactId(), version, "jar"), new BytesContent(
                            Utils.newEmptyMavenPluginJarContent(groupId, model.getArtifactId(), version)));
                }

                Collection<File> classifiedFiles = Arrays
                        .asList(file.getParentFile().listFiles(new FilenameFilter() {
                            @Override
                            public boolean accept(File dir, String name) {
                                return FilenameUtils.getBaseName(name).startsWith(basename + '-');
                            }
                        }));

                for (File classifiedFile : classifiedFiles) {
                    String type = org.codehaus.plexus.util.FileUtils.extension(classifiedFile.getName());
                    String classifier = FilenameUtils.getBaseName(classifiedFile.getName())
                            .substring(basename.length() + 1);

                    Content content;
                    if (classifiedFile.isDirectory()) {
                        content = new DirectoryContent(classifiedFile, lazyArchiver);
                    } else {
                        content = new FileContent(classifiedFile);
                    }

                    set(new Artifact(groupId, model.getArtifactId(), version, classifier, type), content);
                }
            } catch (IOException e) {
                if (log != null) {
                    log.warn("Could not read from " + file, e);
                }
            } catch (XmlPullParserException e) {
                if (log != null) {
                    log.warn("Could not parse " + file, e);
                }
            }
        }

        File archetypeCatalogFile = new File(root, "archetype-catalog.xml");
        if (archetypeCatalogFile.isFile()) {
            archetypeCatalog = new FileContent(archetypeCatalogFile);
        }
    }
}

From source file:org.codehaus.mojo.sysdeo.ide.ReadWorkspaceLocations.java

License:Apache License

/**
 * Scan the eclipse workspace and create a array with {@link IdeDependency} for all found artifacts.
 *
 * @param workspaceLocation the location of the eclipse workspace.
 * @param logger the logger to report errors and debug info.
 *//*from   ww w . jav  a2s  . co  m*/
public List readWorkspace(File workspacePath, Log logger) {
    ArrayList dependencys = new ArrayList();
    if (workspacePath != null) {
        File workspace = new File(workspacePath,
                ReadWorkspaceLocations.METADATA_PLUGINS_ORG_ECLIPSE_CORE_RESOURCES_PROJECTS);

        File[] directories = workspace.listFiles();
        for (int index = 0; directories != null && index < directories.length; index++) {
            File project = directories[index];
            if (project.isDirectory()) {
                try {
                    String projectLocation = getProjectLocation(workspacePath, project);
                    if (projectLocation != null) {
                        IdeDependency ideDependency = readArtefact(projectLocation, logger);
                        if (ideDependency != null) {
                            logger.debug("Read workspace project " + ideDependency);
                            ideDependency.setIdeProjectName(project.getName());
                            dependencys.add(ideDependency);
                        }
                    }
                } catch (Exception e) {
                    logger.warn("could not read workspace project:" + project, e);
                }
            }
        }
    }
    return dependencys;
}

From source file:org.codehaus.mojo.versions.api.DefaultVersionsHelper.java

License:Apache License

private static RuleSet loadRuleSet(String serverId, Settings settings, WagonManager wagonManager,
        String rulesUri, Log logger) throws MojoExecutionException {
    RuleSet ruleSet = new RuleSet();
    if (rulesUri != null && rulesUri.trim().length() != 0) {
        try {/*from   www  .  j  a  v  a  2  s.  c  o m*/
            int split = rulesUri.lastIndexOf('/');
            String baseUri;
            String fileUri;
            if (split != -1) {
                baseUri = rulesUri.substring(0, split) + '/';
                fileUri = split + 1 < rulesUri.length() ? rulesUri.substring(split + 1) : "";
            } else {
                baseUri = rulesUri;
                fileUri = "";
            }
            try {
                Wagon wagon = WagonUtils.createWagon(serverId, baseUri, wagonManager, settings, logger);
                try {
                    logger.debug("Trying to load ruleset from file \"" + fileUri + "\" in " + baseUri);
                    final RuleSet loaded = getRuleSet(wagon, fileUri);
                    ruleSet.setRules(loaded.getRules());
                    ruleSet.setIgnoreVersions(loaded.getIgnoreVersions());
                    logger.debug("Rule set loaded");
                } finally {
                    if (wagon != null) {
                        try {
                            wagon.disconnect();
                        } catch (ConnectionException e) {
                            logger.warn("Could not disconnect wagon!", e);
                        }
                    }

                }
            } catch (TransferFailedException e) {
                throw new MojoExecutionException("Could not transfer rules from " + rulesUri, e);
            } catch (AuthorizationException e) {
                throw new MojoExecutionException("Authorization failure trying to load rules from " + rulesUri,
                        e);
            } catch (ResourceDoesNotExistException e) {
                throw new MojoExecutionException("Could not load specified rules from " + rulesUri, e);
            } catch (AuthenticationException e) {
                throw new MojoExecutionException("Authentication failure trying to load rules from " + rulesUri,
                        e);
            } catch (UnsupportedProtocolException e) {
                throw new MojoExecutionException("Unsupported protocol for " + rulesUri, e);
            } catch (ConnectionException e) {
                throw new MojoExecutionException("Could not establish connection to " + rulesUri, e);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Could not load specified rules from " + rulesUri, e);
        }
    }
    return ruleSet;
}

From source file:org.jasig.maven.notice.AbstractNoticeMojo.java

License:Apache License

/**
 * Check if there are any unresolved artifacts in the Set. If there are print a helpful error
 * message and then throw a {@link MojoFailureException}
 *//*from   w w  w.  j a  v  a2s.c om*/
protected void checkUnresolved(Set<Artifact> unresolvedArtifacts) throws MojoFailureException {
    final Log logger = this.getLog();

    if (unresolvedArtifacts.isEmpty()) {
        return;
    }

    final LicenseLookup licenseLookup = new LicenseLookup();
    final List<ArtifactLicense> artifacts = licenseLookup.getArtifact();

    logger.error("Failed to find Licenses for the following dependencies: ");
    for (final Artifact unresolvedArtifact : unresolvedArtifacts) {
        logger.error("\t" + unresolvedArtifact);

        //Build LicenseLookup data model for artifacts that failed resolution
        final ArtifactLicense artifactLicense = new ArtifactLicense();
        artifactLicense.setGroupId(unresolvedArtifact.getGroupId());
        artifactLicense.setArtifactId(unresolvedArtifact.getArtifactId());

        final List<MappedVersion> mappedVersions = artifactLicense.getVersion();
        final MappedVersion mappedVersion = new MappedVersion();
        mappedVersion.setValue(unresolvedArtifact.getVersion());
        mappedVersions.add(mappedVersion);

        artifacts.add(artifactLicense);
    }
    logger.error("Try adding them to a 'licenseMapping' file.");

    final File buildDir = new File(project.getBuild().getDirectory());
    final File mappingsfile = new File(buildDir, "license-mappings.xml");

    //Make sure the target directory exists
    try {
        FileUtils.forceMkdir(buildDir);
    } catch (IOException e) {
        logger.warn("Failed to write stub license-mappings.xml file to: " + mappingsfile, e);
    }

    //Write the example mappings file
    final Marshaller marshaller = LicenseLookupContext.getMarshaller();
    try {
        marshaller.marshal(licenseLookup, mappingsfile);
        logger.error(
                "A stub license-mapping.xml file containing the unresolved dependencies has been written to: "
                        + mappingsfile);
    } catch (JAXBException e) {
        logger.warn("Failed to write stub license-mappings.xml file to: " + mappingsfile, e);
    }

    throw new MojoFailureException("Failed to find Licenses for " + unresolvedArtifacts.size() + " artifacts");
}

From source file:org.jasig.maven.notice.CheckNoticeMojo.java

License:Apache License

@Override
protected void handleNotice(ResourceFinder finder, String noticeContents) throws MojoFailureException {
    final Log logger = this.getLog();

    //Write out the generated notice file
    final File outputFile = getNoticeOutputFile();

    //Make sure the existing NOTICE file exists
    if (!outputFile.exists()) {
        throw new MojoFailureException("No NOTICE file exists at: " + outputFile);
    }//from w  w  w .j  a  va2 s.  c  o  m

    //Load up the existing NOTICE file
    final Reader existingNoticeContents;
    try {
        final FileInputStream outputFileInputStream = new FileInputStream(outputFile);
        existingNoticeContents = new InputStreamReader(new BufferedInputStream(outputFileInputStream),
                this.encoding);
    } catch (IOException e) {
        throw new MojoFailureException("Failed to read existing NOTICE File from: " + outputFile, e);
    }

    //Check if the notice files match
    final String diffText = this.generateDiff(logger, new StringReader(noticeContents), existingNoticeContents);
    if (diffText.length() != 0) {
        final String buildDir = project.getBuild().getDirectory();
        final File expectedNoticeFile = new File(new File(buildDir), "NOTICE.expected");
        try {
            FileUtils.writeStringToFile(expectedNoticeFile, noticeContents, this.encoding);
        } catch (IOException e) {
            logger.warn("Failed to write expected NOTICE File to: " + expectedNoticeFile, e);
        }

        final String msg = "Existing NOTICE file '" + outputFile + "' doesn't match expected NOTICE file: "
                + expectedNoticeFile;
        logger.error(msg + "\n" + diffText);
        throw new MojoFailureException(msg);
    }

    logger.info("NOTICE file is up to date");
}

From source file:org.jasig.maven.notice.CheckNoticeMojo.java

License:Apache License

protected String generateDiff(Log logger, Reader noticeContents, Reader existingNoticeContents) {
    final StringBuilder diffText = new StringBuilder();
    try {//from ww w  . j  a v a  2 s  .  c o  m
        final List<?> expectedLines = IOUtils.readLines(noticeContents);
        final List<?> existingLines = IOUtils.readLines(existingNoticeContents);
        final Patch diff = DiffUtils.diff(expectedLines, existingLines);

        for (final Delta delta : diff.getDeltas()) {
            final Chunk original = delta.getOriginal();
            final Chunk revised = delta.getRevised();

            final char changeType;
            if (delta instanceof DeleteDelta) {
                changeType = 'd';
            } else if (delta instanceof InsertDelta) {
                changeType = 'a';
            } else if (delta instanceof ChangeDelta) {
                changeType = 'c';
            } else {
                changeType = '?';
            }

            //Write out the diff line info
            diffText.append(original.getPosition() + 1);
            if (original.getLines().size() > 1) {
                diffText.append(",").append(original.getPosition() + original.getLines().size());
            }
            diffText.append(changeType);
            diffText.append(revised.getPosition() + 1);
            if (revised.getLines().size() > 1) {
                diffText.append(",").append(revised.getPosition() + revised.getLines().size());
            }
            diffText.append("\n");

            //Write out the incoming and outgoing changes
            for (final Object line : original.getLines()) {
                diffText.append("< ").append(line).append("\n");
            }
            diffText.append("---\n");
            for (final Object line : revised.getLines()) {
                diffText.append("> ").append(line).append("\n");
            }
        }
    } catch (IOException e) {
        logger.warn("Failed to generate diff between existing and expected NOTICE files", e);
    }
    return diffText.toString();
}