Example usage for org.apache.maven.project MavenProject getBuild

List of usage examples for org.apache.maven.project MavenProject getBuild

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getBuild.

Prototype

public Build getBuild() 

Source Link

Usage

From source file:com.liferay.ide.maven.core.MavenBundlePluginProject.java

License:Open Source License

@Override
public IPath getOutputBundle(boolean cleanBuild, IProgressMonitor monitor) throws CoreException {
    IPath outputJar = null;/* w ww  .  j  ava 2 s  .c  o m*/

    final IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(getProject(), monitor);
    final MavenProjectBuilder mavenProjectBuilder = new MavenProjectBuilder(this.getProject());

    // IDE-3009 delete the MANIFEST.MF to ensure that it will be regenerated by bnd-process

    IFile manifest = this.getProject().getFile("target/classes/META-INF/MANIFEST.MF");

    if (manifest.exists()) {
        manifest.delete(true, monitor);
    }

    if (cleanBuild || !isAutoBuild()) {
        this.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
        this.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    }

    mavenProjectBuilder.execJarMojo(projectFacade, monitor);

    final MavenProject mavenProject = projectFacade.getMavenProject(monitor);

    final String targetName = mavenProject.getBuild().getFinalName() + ".jar";

    final String buildDirectory = mavenProject.getBuild().getDirectory();
    final File baseDirectory = mavenProject.getBasedir();

    final IPath buildDirPath = new Path(buildDirectory);
    final IPath baseDirPath = new Path(baseDirectory.toString());

    final IPath relativePath = buildDirPath.makeRelativeTo(baseDirPath);

    final IFolder targetFolder = getTargetFolder(getProject(), relativePath);

    if (targetFolder.exists()) {
        // targetFolder.refreshLocal( IResource.DEPTH_ONE, monitor );
        final IPath targetFile = targetFolder.getRawLocation().append(targetName);

        if (targetFile.toFile().exists()) {
            outputJar = targetFile;
        }
    }

    return outputJar;
}

From source file:com.liferay.ide.maven.core.MavenProjectRemoteServerPublisher.java

License:Open Source License

public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    IPath retval = null;//from   w ww . j  a  v  a 2  s.  c o  m

    if (runMavenGoal(getProject(), monitor)) {
        final IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(getProject(), monitor);
        final MavenProject mavenProject = projectFacade.getMavenProject(monitor);
        final String targetFolder = mavenProject.getBuild().getDirectory();
        final String targetWar = mavenProject.getBuild().getFinalName() + "." + mavenProject.getPackaging();

        retval = new Path(targetFolder).append(targetWar);
    }

    return retval;
}

From source file:com.liferay.ide.maven.core.MavenUtil.java

License:Open Source License

public static IPath getM2eLiferayFolder(MavenProject mavenProject, IProject project) {
    String buildOutputDir = mavenProject.getBuild().getDirectory();
    String relativeBuildOutputDir = ProjectUtils.getRelativePath(project, buildOutputDir);

    return new Path(relativeBuildOutputDir).append(ILiferayMavenConstants.M2E_LIFERAY_FOLDER);
}

From source file:com.mcleodmoores.mvn.natives.PackageMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().debug("Skipping step");
        return;//from w w  w .  j  av  a  2  s .  c o m
    }
    applyDefaults();
    final MavenProject project = (MavenProject) getPluginContext().get("project");
    final File targetDir = new File(project.getBuild().getDirectory());
    targetDir.mkdirs();
    final File targetFile = new File(targetDir, project.getArtifactId() + ".zip");
    getLog().debug("Writing to " + targetFile);
    final OutputStream output;
    try {
        output = getOutputStreams().open(targetFile);
    } catch (final IOException e) {
        throw new MojoFailureException("Can't write to " + targetFile);
    }
    final IOExceptionHandler errorLog = new MojoLoggingErrorCallback(this);
    if ((new IOCallback<OutputStream, Boolean>(output) {

        @Override
        protected Boolean apply(final OutputStream output) throws IOException {
            final byte[] buffer = new byte[4096];
            final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(output));
            for (final Map.Entry<Source, String> sourceInfo : gatherSources().entrySet()) {
                final Source source = sourceInfo.getKey();
                getLog().info("Processing " + source.getPath() + " into " + sourceInfo.getValue() + " ("
                        + source.getPattern() + ")");
                final File folder = new File(source.getPath());
                final String[] files = folder.list(new PatternFilenameFilter(regex(source.getPattern())));
                if (files != null) {
                    for (final String file : files) {
                        getLog().debug("Adding " + file + " to archive");
                        final ZipEntry entry = new ZipEntry(sourceInfo.getValue() + file);
                        zip.putNextEntry(entry);
                        if ((new IOCallback<InputStream, Boolean>(
                                getInputStreams().open(new File(folder, file))) {

                            @Override
                            protected Boolean apply(final InputStream input) throws IOException {
                                int bytes;
                                while ((bytes = input.read(buffer, 0, buffer.length)) > 0) {
                                    zip.write(buffer, 0, bytes);
                                }
                                return Boolean.TRUE;
                            }

                        }).call(errorLog) != Boolean.TRUE) {
                            return Boolean.FALSE;
                        }
                        zip.closeEntry();
                    }
                } else {
                    getLog().debug("Source folder is empty or does not exist");
                }
            }
            zip.close();
            return Boolean.TRUE;
        }

    }).call(errorLog) != Boolean.TRUE) {
        throw new MojoFailureException("Error writing to " + targetFile);
    }
    project.getArtifact().setFile(targetFile);
}

From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().debug("Skipping step");
        return;//w  w w  .ja v a 2  s  . c om
    }
    final MavenProject project = (MavenProject) getPluginContext().get("project");
    final File targetDir = new File(new File(project.getBuild().getDirectory()), "dependency");
    targetDir.mkdirs();
    final Map<String, Set<Artifact>> names = new HashMap<String, Set<Artifact>>();
    for (final Artifact artifact : project.getArtifacts()) {
        if (isNative(artifact)) {
            gatherNames(artifact, names);
        }
    }
    for (final Artifact artifact : project.getArtifacts()) {
        if (isNative(artifact)) {
            unpack(artifact, names, targetDir);
        }
    }
}

From source file:com.mebigfatguy.fbp.FBPMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {

    if (executed) {
        return;//  ww  w. j  a  va2 s. com
    }
    executed = true;

    try (PrintWriter pw = getFBPStream()) {

        pw.println("<Project projectName=\"" + project.getName() + "\">");

        List<MavenProject> projects = session.getProjectDependencyGraph().getSortedProjects();

        Set<String> jars = new TreeSet<>();
        for (MavenProject module : projects) {
            jars.add(module.getBuild().getOutputDirectory());
        }

        for (String jar : jars) {
            pw.println("\t<Jar>" + makeRelativePath(jar) + "</Jar>");
        }

        Set<Dependency> dependencies = new TreeSet<>(new DependencyComparator());
        for (MavenProject module : projects) {
            dependencies.addAll(module.getDependencies());
        }

        String localRepo = settings.getLocalRepository();
        if (!localRepo.endsWith("/") && !localRepo.endsWith("\\")) {
            localRepo += "/";
        }

        for (Dependency dependency : dependencies) {
            pw.println("\t<AuxClasspathEntry>" + localRepo + dependency.getGroupId().replace('.', '/') + "/"
                    + dependency.getArtifactId() + "/" + dependency.getVersion() + "/"
                    + dependency.getArtifactId() + "-" + dependency.getVersion() + "." + dependency.getType()
                    + "</AuxClasspathEntry>");
        }

        Set<String> srcRoots = new TreeSet<>();
        for (MavenProject module : projects) {
            srcRoots.addAll(module.getCompileSourceRoots());
        }

        for (String srcRoot : srcRoots) {
            pw.println("\t<SrcDir>" + makeRelativePath(srcRoot) + "</SrcDir>");
        }

        pw.println("</Project>");

    } catch (IOException e) {
        throw new MojoExecutionException("Failed to generate fbp file", e);
    }
}

From source file:com.napramirez.relief.maven.plugins.GenerateConfigurationMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    try {//from   ww  w  . ja  v a  2  s .  co  m
        JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        Configuration configuration = new Configuration();

        List<Project> projects = new ArrayList<Project>();
        for (MavenProject mavenProject : reactorProjects) {
            if (!MAVEN_PROJECT_PACKAGING_POM.equals(mavenProject.getPackaging())) {
                Project project = new Project();
                project.setName(mavenProject.getName());

                Jre jre = new Jre();
                String jrePath = System.getenv(ENV_VAR_JAVA_HOME);
                if (jrePath != null && !jrePath.trim().isEmpty()) {
                    jre.setPath(jrePath);
                }
                project.setJre(jre);

                project.setBuildDirectory(mavenProject.getBuild().getOutputDirectory());
                project.setSources(mavenProject.getCompileSourceRoots());

                Library library = new Library();
                library.setFullPath(mavenProject.getCompileClasspathElements());

                project.setLibrary(library);
                projects.add(project);
            }
        }

        configuration.setProjects(projects);

        if (!outputDirectory.exists() || !outputDirectory.isDirectory()) {
            if (!outputDirectory.mkdirs()) {
                throw new IOException("Failed to create directory " + outputDirectory.getAbsolutePath());
            }
        }

        File outputFile = new File(outputDirectory, outputFilename);

        marshaller.marshal(configuration, outputFile);

        getLog().info("Successfully generated configuration file " + outputFilename);
    } catch (JAXBException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.ning.maven.plugins.duplicatefinder.DuplicateFinderMojo.java

License:Apache License

private File getLocalProjectPath(Artifact artifact) throws DependencyResolutionRequiredException {
    String refId = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
    MavenProject owningProject = (MavenProject) project.getProjectReferences().get(refId);

    if (owningProject != null) {
        if (artifact.getType().equals("test-jar")) {
            File testOutputDir = new File(owningProject.getBuild().getTestOutputDirectory());

            if (testOutputDir.exists()) {
                return testOutputDir;
            }/*w  w  w .j ava  2 s  .c om*/
        } else {
            return new File(project.getBuild().getOutputDirectory());
        }
    }
    return null;
}

From source file:com.opengamma.maven.MojoUtils.java

License:Open Source License

/**
 * Calculates the String classpath for the project.
 * /* w  ww .j ava2  s . c om*/
 * @param project  the project, not null
 * @return the classpath string, not null
 */
public static String calculateRuntimeClasspath(MavenProject project) {
    @SuppressWarnings("unchecked")
    List<Artifact> artifacts = new ArrayList<>(project.getRuntimeArtifacts());
    List<String> cpStrs = new ArrayList<>();
    cpStrs.add(new File(project.getBuild().getOutputDirectory()).getAbsolutePath());
    for (Artifact artifact : artifacts) {
        cpStrs.add(artifact.getFile().getAbsolutePath());
    }
    cpStrs.removeAll(Collections.singleton(""));
    return Joiner.on(File.pathSeparator).join(cpStrs);
}

From source file:com.opengamma.maven.MojoUtils.java

License:Open Source License

/**
 * Calculates the String classpath for the project.
 * /*  w  w  w.  ja va  2s  . c  o  m*/
 * @param project  the project, not null
 * @return the classpath string, not null
 */
public static ClassLoader calculateRuntimeClassLoader(MavenProject project) {
    try {
        @SuppressWarnings("unchecked")
        List<Artifact> artifacts = new ArrayList<>(project.getRuntimeArtifacts());
        List<URL> urlList = new ArrayList<>();
        urlList.add(new File(project.getBuild().getOutputDirectory()).getAbsoluteFile().toURI().toURL());
        for (Artifact artifact : artifacts) {
            urlList.add(artifact.getFile().getAbsoluteFile().toURI().toURL());
        }
        URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);
        return new URLClassLoader(urls);
    } catch (MalformedURLException ex) {
        throw new RuntimeException(ex);
    }
}