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:io.teecube.t3.GenericReplacerMojo.java

License:Apache License

private InvocationRequest getInvocationRequest(MavenProject p) throws MojoExecutionException, IOException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(p.getFile());
    if (p.isExecutionRoot() && !p.getModel().getModules().isEmpty()) {
        request.setGoals(Lists.newArrayList("gpg:sign"));
    } else {//from   w ww  .j a v  a 2s.  c o m
        File gpgDirectory = Files.createTempDir();
        request.setGoals(Lists.newArrayList("gpg:sign-and-deploy-file"));
        Properties properties = new Properties();
        properties.put("file", p.getFile().getAbsolutePath());
        //         properties.put("pomFile", p.getFile().getAbsolutePath());
        properties.put("groupId", p.getGroupId());
        properties.put("artifactId", p.getArtifactId());
        properties.put("version", p.getVersion());
        properties.put("repositoryId", "null");
        properties.put("url", gpgDirectory.toURI().toURL().toString());
        request.setProperties(properties);
    }
    request.setRecursive(false);
    this.tempSettingsFile = createAndSetTempSettings(request);
    return request;
}

From source file:net.java.jpatch.maven.common.AbstractMavenMojo.java

License:Apache License

/**
 * Build MAVEN project.//from  w w  w.j a v  a  2s . com
 * 
 * @param project the MAVEN project.
 * @param buildGoals the goals;
 * @param buildProfiles the profiles;
 * 
 * @return the build summary.
 */
private BuildSummary buildMavenProject(MavenProject project, List<String> buildGoals,
        List<String> buildProfiles) {
    BuildSummary result;
    InvocationRequest request = new InvocationBuildRequest();
    request.setPomFile(project.getFile());
    request.setGoals(buildGoals);
    request.setRecursive(false);
    request.setProfiles(buildProfiles);
    request.setProperties(properties);

    Date startTime = new Date();
    try {
        getLog().info("");
        getLog().info("Build project [" + project.getId() + "]");
        getLog().info("Command " + new MavenCommandLineBuilder().build(request));
        getLog().info("");

        InvocationResult invokerResult = invoker.execute(request);
        if (invokerResult.getExecutionException() != null) {
            throw invokerResult.getExecutionException();
        }
        if (invokerResult.getExitCode() != 0) {
            throw new MojoFailureException("Exit code was " + invokerResult.getExitCode());
        }
        result = new BuildSuccess(project, new Date().getTime() - startTime.getTime());
    } catch (Exception e) {
        Date finished = new Date();
        result = new BuildFailure(project, finished.getTime() - startTime.getTime(), e);
    }
    return result;
}

From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java

License:Apache License

/**
 * Adds the hash entry for the POM./*from  w w w  .  j a v  a  2s.  c  o m*/
 * @param hashBaseNames to add the entry to.
 * @throws IOException when the POM could not be read.
 */
void addHashEntryForPom(final List<String> hashBaseNames) throws IOException {
    final MavenProject project = getProject();
    final HashCode sha1OfPom = Files.hash(project.getFile(), sha1);
    final String pomLine = String.format(Locale.ENGLISH, "%s  %s-%s.pom", sha1OfPom, project.getArtifactId(),
            project.getVersion());
    hashBaseNames.add(pomLine);
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

/**
 * Same as deployPrerelease, but the working directory is not the checkout of the prerelease. Instead, the original user checkout
 * (or a temporary checkout for bare commands) is used, and this, the pom file is the original snapshot pom file.
 *
 * Alternative implementations://from   w  w  w  .  j a  va2  s.c  o  m
 * a) direct code with ArtifactDeployer
 *    - cannot use normal deploy configuration (e.g. addtional goal tied to the deploy phase)
 *    - cannot deploy more than one file at a time
 * b) deploy-file invocation
 *    - cannot use normal deploy configuration (e.g. addtional goal tied to the deploy phase)
 */
public void deploySnapshot(Maven maven, Log log, Map<String, String> userProperties,
        MavenProject originalProject) throws Exception {
    maven.deploySnapshot(checkout.getWorld().file(originalProject.getFile()).getParent(), log, userProperties,
            this);
}

From source file:net.oneandone.maven.rules.common.AbstractRule.java

License:Apache License

private boolean projectIsSubmodule(MavenProject project, Log log) {
    final MavenProject parent = project.getParent();
    if (parent != null) {
        for (String module : parent.getOriginalModel().getModules()) {
            final File parentProjectWithModule = new File(parent.getFile().getParentFile(), module);
            log.warn("project Parent + sub: " + parentProjectWithModule);
            final File projectParentFolder = project.getFile().getParentFile();
            log.warn("project file" + projectParentFolder);
            if (parentProjectWithModule.equals(projectParentFolder)) {
                return true;
            }//from   w w w  . j  av  a  2s . c om
        }
    }
    return false;
}

From source file:org.apache.tuscany.maven.plugin.eclipse.EclipsePlugin.java

License:Apache License

public final EclipseSourceDir[] buildDirectoryList(MavenProject project, File basedir,
        File buildOutputDirectory) throws MojoExecutionException {
    File projectBaseDir = project.getFile().getParentFile();

    String mainOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir, buildOutputDirectory, false);

    // If using the standard output location, don't mix the test output into it.
    String testOutput = null;//from   w ww  .j  ava2s .c o m
    boolean useStandardOutputDir = buildOutputDirectory
            .equals(new File(project.getBuild().getOutputDirectory()));
    if (useStandardOutputDir) {
        getLog().debug("testOutput toRelativeAndFixSeparator " + projectBaseDir + " , "
                + project.getBuild().getTestOutputDirectory());
        testOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir,
                new File(project.getBuild().getTestOutputDirectory()), false);
        getLog().debug("testOutput after toRelative : " + testOutput);
    }

    Set mainDirectories = new LinkedHashSet();

    extractSourceDirs(mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null);

    extractResourceDirs(mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false,
            mainOutput);

    Set testDirectories = new LinkedHashSet();

    extractSourceDirs(testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true,
            testOutput);

    extractResourceDirs(testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true,
            testOutput);

    // avoid duplicated entries
    Set directories = new LinkedHashSet();

    // NOTE: Since MNG-3118, test classes come before main classes
    boolean testBeforeMain = isMavenVersion("[2.0.8,)");

    if (testBeforeMain) {
        directories.addAll(testDirectories);
        directories.removeAll(mainDirectories);
        directories.addAll(mainDirectories);
    } else {
        directories.addAll(mainDirectories);
        directories.addAll(testDirectories);
    }
    if (ajdt)
        extractAspectDirs(directories, project, basedir, projectBaseDir, testOutput);
    return (EclipseSourceDir[]) directories.toArray(new EclipseSourceDir[directories.size()]);
}

From source file:org.arakhne.maven.plugins.atomicdeploy.JavadocMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w  w w  .  j a v  a  2  s. c om*/
 */
@Override
public synchronized void executeMojo() throws MojoExecutionException {
    MavenProject project = this.mavenSession.getCurrentProject();
    File javadocDir = new File(this.javadocDirectory);
    File indexFile = new File(javadocDir, "index.html"); //$NON-NLS-1$
    if (javadocDir.isDirectory() && indexFile.isFile()) {
        URL deployementURL = getInheritedSiteDeploymentURL(project, this.targetDirectoryName);
        BuildContext buildContext = getBuildContext();
        buildContext.removeMessages(project.getFile());
        if (deployementURL != null) {
            if ("file".equalsIgnoreCase(deployementURL.getProtocol())) { //$NON-NLS-1$
                File output = new File(deployementURL.getPath());
                getLog().info("Input: " + javadocDir); //$NON-NLS-1$
                getLog().info("Output: " + output); //$NON-NLS-1$
                try {
                    dirRemove(output);
                    dirCopy(javadocDir, output, true);
                } catch (IOException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
            } else {
                String message = "Unsupported transport protocol: " + deployementURL.getProtocol(); //$NON-NLS-1$
                buildContext.addMessage(project.getFile(), 1, 1, message, BuildContext.SEVERITY_ERROR, null);
            }
        } else {
            String message = "No site deployement URL found"; //$NON-NLS-1$
            buildContext.addMessage(project.getFile(), 1, 1, message, BuildContext.SEVERITY_ERROR, null);
        }
    } else {
        getLog().info("Skipping project, no javadoc directory found"); //$NON-NLS-1$
    }
}

From source file:org.automagic.deps.doctor.editor.PomWriterImpl.java

License:Apache License

public PomWriterImpl(MavenProject project, int indentationSize, boolean indentWithTabs, boolean addComments) {
    this.indentationSize = indentationSize;
    this.addComments = addComments;
    this.project = project;
    this.document = Utils.getDocument(project.getFile());
    this.indentWithTabs = indentWithTabs;
}

From source file:org.automagic.deps.doctor.spy.PomSpyImpl.java

License:Apache License

public PomSpyImpl(MavenProject project, ArtifactRepository repository, ArtifactFactory factory,
        ArtifactMetadataSource metadataSource, ArtifactCollector collector, DependencyTreeBuilder treeBuilder,
        boolean useParent) {
    this.project = project;
    this.repository = repository;
    this.factory = factory;
    this.metadataSource = metadataSource;
    this.collector = collector;
    this.treeBuilder = treeBuilder;
    this.useParent = useParent;
    this.document = Utils.getDocument(project.getFile());
}

From source file:org.codehaus.cargo.documentation.ConfluenceProjectStructureDocumentationGenerator.java

License:Apache License

/**
 * Writes the current MavenProject information.
 * @param aProject the MavenProject we are currently documenting.
 * @param treeIndex the current project level.
 * @return the markup for the given MavenProject.
 *///from  w  w  w. j  a v a 2s . c o  m
private String getProjectInfo(MavenProject aProject, int treeIndex) {
    StringBuilder markup = new StringBuilder("");

    markup.append(ASTERISK);
    markup.append(" ");
    markup.append(START_COLOR);
    markup.append(aProject.getFile().getParentFile().getName());
    markup.append("/");
    markup.append(END_COLOR);

    String description = aProject.getDescription() != null ? aProject.getDescription() : aProject.getName();
    markup.append(": ");
    markup.append(description);
    markup.append(LINE_SEPARATOR);

    markup.append(getModuleTree(aProject, treeIndex));

    return markup.toString();
}