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

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

Introduction

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

Prototype

public File getFile() 

Source Link

Usage

From source file:org.jszip.maven.RunMojo.java

License:Apache License

private long getPomsLastModified() {
    long result = Long.MIN_VALUE;
    for (MavenProject p : reactorProjects) {
        result = Math.max(p.getFile().lastModified(), result);
    }// w  w  w.  ja  va  2  s .c o  m
    return result;
}

From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java

License:Apache License

public static File getStandardPom(MavenProject project) {
    if (project == null) {
        return null;
    }/*from   w w w.  j a v  a2 s  .c om*/

    File pom = project.getFile();

    if (pom == null) {
        return null;
    }

    return pom;
}

From source file:org.levigo.m2e.assertj.internal.AssertJBuildParticipant.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w  w  .j  a  v a2s . c om*/
public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
    final BuildContext buildContext = getBuildContext();

    MavenProject mavenProject = getMavenProjectFacade().getMavenProject(monitor);

    List<String> classpathElements = new ArrayList<String>(mavenProject.getCompileClasspathElements());
    classpathElements.addAll(mavenProject.getTestClasspathElements());

    ClassFileMatcher deltaScanner = new ClassFileMatcher(//
            (List<String>) getMojoParameterValue("packages", List.class, monitor),
            (List<String>) getMojoParameterValue("classes", List.class, monitor),
            (List<String>) getMojoParameterValue("includes", List.class, monitor),
            (List<String>) getMojoParameterValue("excludes", List.class, monitor));

    boolean foundDelta = false;

    // Check for POM change
    Scanner pomScanner = buildContext.newScanner(mavenProject.getFile());
    pomScanner.scan();
    if (pomScanner.getIncludedFiles().length > 0) {
        log.info("###################### Found pom change");

        cleanTargetFolder(monitor);
        foundDelta = true;
    }

    // Check for resource change
    if (!foundDelta)
        for (String classpathElement : classpathElements) {
            File f = new File(classpathElement);
            if (f.isDirectory()) {
                String[] deletions = buildContext.newDeleteScanner(f).getIncludedFiles();
                if (null != deletions && deletions.length > 0) {
                    log.info("###################### Found deletion in " + f);

                    cleanTargetFolder(monitor);
                    foundDelta = true;
                    break;
                } else {
                    Scanner ds = buildContext.newScanner(f);
                    ds.scan();
                    String[] includedFiles = ds.getIncludedFiles();
                    if (includedFiles != null)
                        for (String file : includedFiles) {
                            foundDelta |= deltaScanner.matches(file);
                            log.info("###################### Found matching class file " + file + ": "
                                    + foundDelta);
                            break;
                        }
                }
                log.info("###################### Check for delta in " + f + ": " + foundDelta);
            }

            if (foundDelta)
                break;
        }

    if (!foundDelta) {
        log.info("No changes");
        return null;
    }

    log.info("Running template generation");

    // execute mojo
    Set<IProject> result = super.build(kind, monitor);

    // tell m2e builder to refresh generated files
    final File generated = getTargetDir(monitor);
    if (generated != null) {
        buildContext.refresh(generated);

        /*
         * For some weird reason the java build triggered by buildContext.refresh(generated) above
         * does not (yet) see the changed class file (although we detected the changed class file
         * result). This causes compile errors upon added/removed/updated fields and properties. We
         * schedule another workspace refresh to correct this situation.
         */
        new Job("Refresh generated assertions") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                log.info("Refreshing generated assertions");

                IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                try {
                    IJobManager jobManager = Job.getJobManager();
                    jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, monitor);
                    jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, monitor);

                    myWorkspaceRoot.getFolder(Path.fromOSString(generated.getAbsoluteFile().getCanonicalPath()))
                            .refreshLocal(IResource.DEPTH_INFINITE, monitor);
                } catch (Exception e) {
                    log.error("Failed to refresh the generated assertions", e);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    }

    return result;
}

From source file:org.lib4j.maven.mojo.Specification.java

License:Open Source License

private static Specification parse(final Xpp3Dom manifest, final MavenProject project)
        throws MojoFailureException {
    if (manifest == null)
        throw new MojoFailureException("Manifest is required");

    File destDir = null;//from ww w .  ja v a 2 s  .  com
    final LinkedHashSet<URL> resources = new LinkedHashSet<>();
    boolean overwrite = true;

    try {
        for (int j = 0; j < manifest.getChildCount(); j++) {
            final Xpp3Dom element = manifest.getChild(j);
            if ("destDir".equals(element.getName())) {
                destDir = Paths.isAbsolute(element.getValue()) ? new File(element.getValue())
                        : new File(project.getBasedir(), element.getValue());
                for (final String attribute : element.getAttributeNames()) {
                    if (attribute.endsWith("overwrite"))
                        overwrite = Boolean.parseBoolean(element.getAttribute(attribute));
                }
            } else if ("resources".equals(element.getName())) {
                for (int k = 0; k < element.getChildCount(); k++) {
                    final Xpp3Dom schema = element.getChild(k);
                    if ("resource".equals(schema.getName())) {
                        resources.add(buildURL(project.getFile().getParentFile().getAbsoluteFile(),
                                schema.getValue()));
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }

    if (destDir == null)
        throw new MojoFailureException("Manifest.destDir is required");

    return new Specification(overwrite, destDir, resources);
}

From source file:org.libx4j.maven.common.Manifest.java

License:Open Source License

private static Manifest parse(final Xpp3Dom manifest, final Plugin plugin, final MavenProject project)
        throws MojoFailureException {
    if (manifest == null)
        throw new MojoFailureException("Manifest is required");

    File destdir = null;/*from w  w  w  .j  a  va  2  s  .co m*/
    final LinkedHashSet<URL> resources = new LinkedHashSet<URL>();
    boolean overwrite = false;
    boolean compile = false;
    boolean pack = false;

    try {
        for (int j = 0; j < manifest.getChildCount(); j++) {
            final Xpp3Dom element = manifest.getChild(j);
            if ("destdir".equals(element.getName())) {
                destdir = Paths.isAbsolute(element.getValue()) ? new File(element.getValue())
                        : new File(project.getBuild().getDirectory(), element.getValue());
                for (final String attribute : element.getAttributeNames()) {
                    if (attribute.endsWith("overwrite"))
                        overwrite = Boolean.parseBoolean(element.getAttribute(attribute));
                    else if (attribute.endsWith("compile"))
                        compile = Boolean.parseBoolean(element.getAttribute(attribute));
                    else if (attribute.endsWith("package"))
                        pack = Boolean.parseBoolean(element.getAttribute(attribute));
                }
            } else if ("resources".equals(element.getName())) {
                for (int k = 0; k < element.getChildCount(); k++) {
                    final Xpp3Dom schema = element.getChild(k);
                    if ("resource".equals(schema.getName())) {
                        resources.add(buildURL(project.getFile().getParentFile().getAbsoluteFile(),
                                schema.getValue()));
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }

    if (destdir == null)
        throw new MojoFailureException("Manifest.destdir is required");

    return new Manifest(overwrite, compile, pack, destdir, resources);
}

From source file:org.maven.ide.eclipse.embedder.EclipseLifecycleExecutor.java

License:Apache License

public static List /*java.util.File*/ getAffectedProjects() {
    Object obj = reactorManager.get();
    if (obj instanceof ReactorManager) {
        ReactorManager rm = (ReactorManager) obj;
        List lst = rm.getSortedProjects();
        Iterator it = lst.iterator();
        List toRet = new ArrayList();
        while (it.hasNext()) {
            MavenProject elem = (MavenProject) it.next();
            toRet.add(elem.getFile());
        }//from  w w  w  .j  a v a 2  s. c  om
        return toRet;
    }
    return Collections.EMPTY_LIST;
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Attempt to repair bundle imports by replacing them with pax-import-bundle commands
 * /*  w  w w. j  a v a 2  s  .c o m*/
 * @param script build script
 * @param project Maven project
 * @return customized Maven project model
 */
private Pom repairBundleImports(PaxScript script, MavenProject project) {
    Pom pom;
    try {
        File tempFile = File.createTempFile("pom", ".xml", m_tempdir);
        FileUtils.copyFile(project.getFile(), tempFile);
        pom = PomUtils.readPom(tempFile);
        tempFile.deleteOnExit();
    } catch (IOException e) {
        pom = null;
    }

    for (Iterator i = project.getDependencies().iterator(); i.hasNext();) {
        Dependency dependency = (Dependency) i.next();

        String bundleId = dependency.getGroupId() + ':' + dependency.getArtifactId();
        String bundleName = (String) m_bundleNameMap.get(bundleId);

        // is this a local bundle project?
        if (null != bundleName) {
            PaxCommandBuilder command;

            command = script.call(PaxScript.IMPORT_BUNDLE);
            command.option('a', bundleName);

            // enable overwrite
            command.flag('o');

            // only apply to the importing bundle project
            setTargetDirectory(command, project.getBasedir());

            if (null != pom) {
                pom.removeDependency(dependency);
            }
        }
    }

    try {
        if (null != pom) {
            pom.write();
        }
        return pom;
    } catch (IOException e) {
        return null;
    }
}

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Install deployment POM in the local Maven repository
 * //w ww  .  j  av  a  2 s .co  m
 * @param project deployment project
 * @throws MojoExecutionException
 */
private void installDeploymentPom(MavenProject project) throws MojoExecutionException {
    String groupId = project.getGroupId();
    String artifactId = project.getArtifactId();
    String version = project.getVersion();

    Artifact pomArtifact = m_factory.createProjectArtifact(groupId, artifactId, version);

    try {
        m_installer.install(project.getFile(), pomArtifact, m_localRepo);
    } catch (ArtifactInstallationException e) {
        throw new MojoExecutionException("Unable to install deployment POM " + pomArtifact);
    }
}

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Deploy bundles using the new Pax-Runner codebase
 * /*from   w  w  w .j a va2s  .com*/
 * @param mainClass main Pax-Runner class
 * @param project deployment project
 * @param repositories comma separated list of Maven repositories
 * @throws MojoExecutionException
 */
private void deployRunnerNG(Class mainClass, MavenProject project, String repositories)
        throws MojoExecutionException {
    List deployAppCmds = getDeployCommands();

    // only apply if explicitly configured
    if (PomUtils.isNotEmpty(framework)) {
        deployAppCmds.add("--platform=" + framework);
    }
    if (PomUtils.isNotEmpty(profiles)) {
        deployAppCmds.add("--profiles=" + profiles);
    }

    if (PomUtils.isNotEmpty(args)) {
        try {
            new URL(args); // check syntax
        } catch (MalformedURLException e) {
            // assume it's a local filename
            File argsFile = new File(args);
            args = argsFile.toURI().toString();
        }

        // custom Pax-Runner arguments file
        deployAppCmds.add("--args=" + args);
    }

    // apply project provision settings before defaults
    deployAppCmds.addAll(Arrays.asList(provision));

    // main deployment pom with project bundles as dependencies
    deployAppCmds.add(project.getFile().getAbsolutePath());

    if (PomUtils.isNotEmpty(deployURLs)) {
        // additional (external) bundle URLs
        String[] urls = deployURLs.split(",");
        for (int i = 0; i < urls.length; i++) {
            deployAppCmds.add(urls[i].trim());
        }
    }

    // use project settings to access remote/local repositories
    deployAppCmds.add("--localRepository=" + m_localRepo.getBasedir());
    deployAppCmds.add("--repositories=" + repositories);
    deployAppCmds.add("--overwriteUserBundles");

    getLog().debug("Starting Pax-Runner " + runner + " with: " + deployAppCmds.toString());
    invokePaxRunner(mainClass, (String[]) deployAppCmds.toArray(new String[deployAppCmds.size()]));
}

From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java

License:Apache License

/**
 * Add bundle as a dependency to the provisioning POM and the local bundle POM, as appropriate
 * //ww  w. j  ava 2s .com
 * @param project bundle project
 */
private void importBundle(MavenProject project) {
    Dependency dependency = new Dependency();

    dependency.setGroupId(project.getGroupId());
    dependency.setArtifactId(project.getArtifactId());
    dependency.setVersion(project.getVersion());
    dependency.setOptional(!deploy);

    // only add non-local bundles to the provisioning POM
    if (m_provisionPom != null && project.getFile() == null) {
        getLog().info("Importing " + project.getName() + " to " + m_provisionPom);
        m_provisionPom.addDependency(dependency, overwrite);
    }

    if (m_localBundlePom != null) {
        // use provided scope when adding to bundle pom
        dependency.setScope(Artifact.SCOPE_PROVIDED);

        getLog().info("Adding " + project.getName() + " as dependency to " + m_localBundlePom);
        m_localBundlePom.addDependency(dependency, overwrite);
    }
}