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

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

Introduction

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

Prototype

void info(Throwable error);

Source Link

Document

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

Usage

From source file:org.deegree.maven.BuildnumberMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    Properties ps = new Properties();
    ps.put("build.artifactId", project.getArtifactId());
    ps.put("build.by", System.getProperty("user.name"));
    ps.put("build.date", project.getProperties().getProperty("buildTimestamp"));
    ps.put("build.svnrev", project.getProperties().getProperty("buildNumber"));
    FileOutputStream os = null;/*from   w w w  .j av  a  2  s  .c  om*/
    try {
        File out = new File(project.getBasedir(), "target/classes/META-INF/deegree/buildinfo.properties");
        if (!out.getParentFile().exists() && !out.getParentFile().mkdirs()) {
            throw new MojoFailureException("Could not create parent directory for buildinfo.properties.");
        }
        os = new FileOutputStream(out);
        ps.store(os, "generated by deegree-maven-plugin");
        log.info("Wrote " + out);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getLocalizedMessage(), e);
    } finally {
        closeQuietly(os);
    }
}

From source file:org.deegree.maven.CopyMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    if (files == null) {
        log.debug("No files configured.");
        return;// w  w  w .j a  v a 2s.c  om
    }

    File basedir = project.getBasedir();
    for (Copy copy : files) {
        log.info("Copy " + copy.from + " to " + copy.to);
        File from = new File(basedir, copy.from);
        File to = new File(basedir, copy.to);
        if (!to.getParentFile().isDirectory() && !to.getParentFile().mkdirs()) {
            log.warn("Could not create parent directories for " + to + ".");
            continue;
        }
        try {
            copyFile(from, to);
        } catch (IOException e) {
            log.warn("Could not copy " + copy.from + " to " + copy.to + ": " + e.getLocalizedMessage());
            log.debug(e);
        }
    }
}

From source file:org.deegree.maven.utils.ZipUtils.java

License:Open Source License

public static void zipJarDependencies(Set<?> jarDeps, Log log, HashSet<String> visitedFiles,
        ZipOutputStream out) {//w  ww.j av  a  2s.c  o m
    for (Object o : jarDeps) {
        Artifact a = (Artifact) o;
        if (a.getScope() == null || a.getScope().equalsIgnoreCase("runtime")
                || a.getScope().equalsIgnoreCase("compile")) {
            log.info("Adding " + a + " to workspace modules directory.");
            ZipEntry entry = new ZipEntry("modules/" + a.getFile().getName());
            visitedFiles.add("modules/" + a.getFile().getName());
            try {
                out.putNextEntry(entry);
                FileInputStream in = new FileInputStream(a.getFile());
                IOUtils.copy(in, out);
                out.closeEntry();
                in.close();
            } catch (Throwable e) {
                // probably duplicate entry
                continue;
            }
        }
    }
}

From source file:org.deegree.maven.utils.ZipUtils.java

License:Open Source License

public static void integrateWorkspaces(List<Artifact> workspaces, Log log, File target, ZipOutputStream out,
        HashSet<String> visitedFiles) throws Throwable {
    for (Artifact a : workspaces) {
        log.info("Processing files in dependency " + a.getArtifactId());
        File tmp = new File(target, a.getArtifactId());
        FileInputStream in = new FileInputStream(a.getFile());
        try {//from w  ww .ja v  a2  s . co  m
            unzip(in, tmp);
            zip(tmp, out, tmp.getAbsoluteFile().toURI(), visitedFiles);
        } finally {
            closeQuietly(in);
        }
    }
}

From source file:org.deegree.maven.WorkspaceInplaceMojo.java

License:Open Source License

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

    File dir = determineWorkspaceDirectory();

    try {/*from w w w .jav a2  s  .c  o  m*/
        Set<?> workspaces = getDependencyArtifacts(project, artifactResolver, artifactFactory, metadataSource,
                localRepository, "deegree-workspace", true);

        copyDependencies(log, dir);

        for (Object o : workspaces) {
            Artifact a = (Artifact) o;
            log.info("Unpacking workspace " + a.getArtifactId());
            FileInputStream in = new FileInputStream(a.getFile());
            try {
                unzip(in, dir, overwrite);
            } finally {
                closeQuietly(in);
            }
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException("Could not resolve artifact: " + e.getLocalizedMessage(), e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("Could not find artifact: " + e.getLocalizedMessage(), e);
    } catch (InvalidDependencyVersionException e) {
        throw new MojoFailureException("Invalid dependency version: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
        throw new MojoFailureException(
                "Could not extract workspace dependencies in place: " + e.getLocalizedMessage(), e);
    }

}

From source file:org.deegree.maven.WorkspaceInplaceMojo.java

License:Open Source License

private void copyDependencies(Log log, File dir) throws MojoFailureException, IOException,
        ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException {
    Set<?> jarDeps = getDependencyArtifacts(project, artifactResolver, artifactFactory, metadataSource,
            localRepository, "jar", false);

    File modules = new File(dir, "modules");
    if (!jarDeps.isEmpty() && !modules.isDirectory() && !modules.mkdirs()) {
        throw new MojoFailureException("Could not create modules directory in workspace.");
    }/*  ww  w. j  a  v  a  2s.  c o  m*/
    for (Object o : jarDeps) {
        Artifact a = (Artifact) o;
        if (a.getScope() == null || a.getScope().equalsIgnoreCase("runtime")
                || a.getScope().equalsIgnoreCase("compile")) {
            log.info("Copying " + a + " to workspace modules directory.");
            copyFileToDirectory(a.getFile(), modules);
        }
    }
}

From source file:org.deegree.maven.WorkspaceMojo.java

License:Open Source License

private void attachArtifact(Log log, File workspaceFile) {
    log.info("Attaching " + workspaceFile);
    Artifact artifact = project.getArtifact();
    if (artifact.getType() == null || !artifact.getType().equals("deegree-workspace")) {
        DefaultArtifactHandler defHandler = new DefaultArtifactHandler("deegree-workspace");
        artifact = new AttachedArtifact(project.getArtifact(), "deegree-workspace", defHandler);
    }//from   ww  w.j  a v  a2 s  . c om

    artifact.setFile(workspaceFile);
    artifact.setResolved(true);
    if (project.getArtifact().getType() == null
            || !project.getArtifact().getType().equals("deegree-workspace")) {
        project.addAttachedArtifact(artifact);
    }
}

From source file:org.eclipse.acceleo.maven.AcceleoParserMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w w.j  ava2 s  .c  o  m*/
 * 
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    log.info("Acceleo maven stand alone build...");

    log.info("Starting packages registration...");

    URLClassLoader newLoader = null;
    try {
        List<?> runtimeClasspathElements = project.getRuntimeClasspathElements();
        List<?> compileClasspathElements = project.getCompileClasspathElements();
        URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + compileClasspathElements.size()];
        int i = 0;
        for (Object object : runtimeClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the runtime dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        for (Object object : compileClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the compilation dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        newLoader = new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader());
    } catch (DependencyResolutionRequiredException e) {
        log.error(e);
    } catch (MalformedURLException e) {
        log.error(e);
    }

    for (String packageToRegister : this.packagesToRegister) {
        try {
            if (newLoader != null) {
                Class<?> forName = Class.forName(packageToRegister, true, newLoader);
                Field nsUri = forName.getField("eNS_URI");
                Field eInstance = forName.getField("eINSTANCE");

                Object nsURIInvoked = nsUri.get(null);
                if (nsURIInvoked instanceof String) {
                    log.info("Registering package '" + packageToRegister + "'.");
                    AcceleoPackageRegistry.INSTANCE.put((String) nsURIInvoked, eInstance.get(null));
                } else {
                    log.error("The URI field is not a string.");
                }
            }
        } catch (ClassNotFoundException e) {
            log.error(e);
        } catch (IllegalAccessException e) {
            log.error(e);
        } catch (SecurityException e) {
            log.error(e);
        } catch (NoSuchFieldException e) {
            log.error(e);
        }

    }

    log.info("Starting the build sequence for the project '" + this.acceleoProject.getRoot() + "'...");
    log.info("Mapping the pom.xml to AcceleoProject...");

    Preconditions.checkNotNull(this.acceleoProject);
    Preconditions.checkNotNull(this.acceleoProject.getRoot());
    Preconditions.checkNotNull(this.acceleoProject.getEntries());
    Preconditions.checkState(this.acceleoProject.getEntries().size() >= 1);

    File root = this.acceleoProject.getRoot();

    org.eclipse.acceleo.internal.parser.compiler.AcceleoProject aProject = new org.eclipse.acceleo.internal.parser.compiler.AcceleoProject(
            root);
    List<Entry> entries = this.acceleoProject.getEntries();
    Set<AcceleoProjectClasspathEntry> classpathEntries = new LinkedHashSet<AcceleoProjectClasspathEntry>();
    for (Entry entry : entries) {
        File inputDirectory = new File(root, entry.getInput());
        File outputDirectory = new File(root, entry.getOutput());

        log.debug("Input: " + inputDirectory.getAbsolutePath());
        log.debug("Output: " + outputDirectory.getAbsolutePath());

        AcceleoProjectClasspathEntry classpathEntry = new AcceleoProjectClasspathEntry(inputDirectory,
                outputDirectory);
        classpathEntries.add(classpathEntry);
    }
    aProject.addClasspathEntries(classpathEntries);

    List<AcceleoProject> dependencies = this.acceleoProject.getDependencies();
    if (dependencies != null) {
        for (AcceleoProject dependingAcceleoProject : dependencies) {
            File dependingProjectRoot = dependingAcceleoProject.getRoot();
            Preconditions.checkNotNull(dependingProjectRoot);

            org.eclipse.acceleo.internal.parser.compiler.AcceleoProject aDependingProject = new org.eclipse.acceleo.internal.parser.compiler.AcceleoProject(
                    dependingProjectRoot);

            List<Entry> dependingProjectEntries = dependingAcceleoProject.getEntries();
            Set<AcceleoProjectClasspathEntry> dependingClasspathEntries = new LinkedHashSet<AcceleoProjectClasspathEntry>();
            for (Entry entry : dependingProjectEntries) {
                File inputDirectory = new File(root, entry.getInput());
                File outputDirectory = new File(root, entry.getOutput());
                AcceleoProjectClasspathEntry classpathEntry = new AcceleoProjectClasspathEntry(inputDirectory,
                        outputDirectory);
                dependingClasspathEntries.add(classpathEntry);
            }

            aDependingProject.addClasspathEntries(dependingClasspathEntries);
            aProject.addProjectDependencies(Sets.newHashSet(aDependingProject));
        }
    }

    log.info("Adding jar dependencies...");
    List<String> jars = this.acceleoProject.getJars();
    if (jars != null) {
        Set<URI> newDependencies = new LinkedHashSet<URI>();
        for (String jar : jars) {
            log.info("Resolving jar: '" + jar + "'...");
            File jarFile = new File(jar);
            if (jarFile.isFile()) {
                URI uri = URI.createFileURI(jar);
                newDependencies.add(uri);
                log.info("Found jar for '" + jar + "' on the filesystem: '" + jarFile.getAbsolutePath() + "'.");
            } else {
                StringTokenizer tok = new StringTokenizer(jar, ":");

                String groupdId = null;
                String artifactId = null;
                String version = null;

                int c = 0;
                while (tok.hasMoreTokens()) {
                    String nextToken = tok.nextToken();
                    if (c == 0) {
                        groupdId = nextToken;
                    } else if (c == 1) {
                        artifactId = nextToken;
                    } else if (c == 2) {
                        version = nextToken;
                    }

                    c++;
                }

                Set<?> artifacts = this.project.getArtifacts();
                for (Object object : artifacts) {
                    if (object instanceof Artifact) {
                        Artifact artifact = (Artifact) object;
                        if (groupdId != null && groupdId.equals(artifact.getGroupId()) && artifactId != null
                                && artifactId.equals(artifact.getArtifactId())) {
                            if (version != null && version.equals(artifact.getVersion())) {
                                File artifactFile = artifact.getFile();
                                if (artifactFile != null && artifactFile.exists()) {
                                    URI uri = URI.createFileURI(artifactFile.getAbsolutePath());
                                    newDependencies.add(uri);
                                    log.info("Found jar for '" + jar + "' on the filesystem: '" + uri.toString()
                                            + "'.");
                                }
                            } else if (version == null) {
                                File artifactFile = artifact.getFile();
                                if (artifactFile != null && artifactFile.exists()) {
                                    URI uri = URI.createFileURI(artifactFile.getAbsolutePath());
                                    newDependencies.add(uri);
                                    log.info("Found jar for '" + jar + "' on the filesystem: '" + uri.toString()
                                            + "'.");
                                }
                            }
                        }
                    }
                }

                List<?> mavenDependencies = this.project.getDependencies();
                for (Object object : mavenDependencies) {
                    if (object instanceof Dependency) {
                        Dependency dependency = (Dependency) object;
                        if (groupdId != null && groupdId.equals(dependency.getGroupId()) && artifactId != null
                                && artifactId.equals(dependency.getArtifactId())) {
                            if (version != null && version.equals(dependency.getVersion())) {
                                String systemPath = dependency.getSystemPath();
                                if (systemPath != null && new File(systemPath).exists()) {
                                    URI uri = URI.createFileURI(systemPath);
                                    newDependencies.add(uri);
                                    log.info("Found jar for '" + jar + "' on the filesystem: '" + uri.toString()
                                            + "'.");
                                }
                            } else if (version == null) {
                                String systemPath = dependency.getSystemPath();
                                if (systemPath != null && new File(systemPath).exists()) {
                                    URI uri = URI.createFileURI(systemPath);
                                    newDependencies.add(uri);
                                    log.info("Found jar for '" + jar + "' on the filesystem: '" + uri.toString()
                                            + "'.");
                                }
                            }
                        }
                    }
                }
            }
        }
        aProject.addDependencies(newDependencies);
    }

    log.info("Starting parsing...");
    AcceleoParser parser = new AcceleoParser(aProject, this.useBinaryResources, this.usePlatformResourcePath);
    AcceleoParserListener listener = new AcceleoParserListener();
    parser.addListeners(listener);

    // Load and plug the uri resolver
    if (this.uriHandler != null && newLoader != null) {
        try {
            Class<?> forName = Class.forName(this.uriHandler, true, newLoader);
            Object newInstance = forName.newInstance();
            if (newInstance instanceof IAcceleoParserURIHandler) {
                IAcceleoParserURIHandler resolver = (IAcceleoParserURIHandler) newInstance;
                parser.setURIHandler(resolver);
            }
        } catch (ClassNotFoundException e) {
            log.error(e);
        } catch (InstantiationException e) {
            log.error(e);
        } catch (IllegalAccessException e) {
            log.error(e);
        }
    }

    Set<File> builtFiles = parser.buildAll(new BasicMonitor());

    boolean errorFound = false;
    for (File builtFile : builtFiles) {
        Collection<AcceleoParserProblem> problems = parser.getProblems(builtFile);
        Collection<AcceleoParserWarning> warnings = parser.getWarnings(builtFile);

        if (problems.size() > 0) {
            log.info("Errors for file '" + builtFile.getName() + "': " + problems);
            errorFound = true;
        }
        if (warnings.size() > 0) {
            log.info("Warnings for file '" + builtFile.getName() + "': " + warnings);
        }
    }

    if (errorFound && failOnError) {
        throw new MojoExecutionException("Errors have been found during the build of the generator");
    }

    // Removing everything
    AcceleoPackageRegistry.INSTANCE.clear();
    log.info("Build completed.");
}

From source file:org.eclipse.acceleo.maven.launcher.compatibility.AcceleoLauncherMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww w .  j a  va  2 s . c o m*/
 * 
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    log.info("Acceleo maven stand alone generation...");

    log.info("Starting generator class loading...");

    URLClassLoader newLoader = null;
    try {
        List<?> runtimeClasspathElements = project.getRuntimeClasspathElements();
        List<?> compileClasspathElements = project.getCompileClasspathElements();
        URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + compileClasspathElements.size()];
        int i = 0;
        for (Object object : runtimeClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the runtime dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        for (Object object : compileClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the compilation dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        newLoader = new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader());
    } catch (DependencyResolutionRequiredException e) {
        log.error(e);
    } catch (MalformedURLException e) {
        log.error(e);
    }

    try {
        if (newLoader != null) {
            final Class<?> generatorClazz = Class.forName(generatorClass, true, newLoader);

            log.info("Starting the generation sequence for the generator '" + generatorClass + "'...");
            final Method mainMethod = generatorClazz.getMethod("main", String[].class);

            List<String> arguments = new ArrayList<String>(parameters.size() + 2);
            log.info("Model: '" + model + "'");
            arguments.add(model);
            log.info("Output folder: '" + outputFolder + "'");
            arguments.add(outputFolder);
            for (String parameter : parameters) {
                log.info("Parameter: '" + parameter + "'");
                arguments.add(parameter);
            }

            log.info("Invoking generator.");
            mainMethod.invoke(null, (Object) arguments.toArray(new String[arguments.size()]));

            log.info("Generation completed.");
        }
    } catch (ClassNotFoundException e) {
        log.error(e);
    } catch (SecurityException e) {
        log.error(e);
    } catch (NoSuchMethodException e) {
        log.error(e);
    } catch (IllegalAccessException e) {
        log.error(e);
    } catch (IllegalArgumentException e) {
        log.error(e);
    } catch (InvocationTargetException e) {
        log.error(e);
    }

}

From source file:org.eclipse.hudson.maven.plugins.hpi.HpiUtil.java

License:Open Source License

static String findHudsonVersion(Collection<Artifact> artifacts, Log log) {
    for (Artifact a : artifacts) {
        if ((HUDSON_CORE_GROUP_ID.equals(a.getGroupId()))
                && HUDSON_CORE_ARTIFACT_ID.equals(a.getArtifactId())) {
            log.info("Targeting Hudson-Version: " + a.getVersion());
            return a.getVersion();
        }//from   w w w .  ja v a 2 s.  c  o  m
    }
    log.warn("Cannot determine Hudson-Version from project dependencies");
    return null;
}