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

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

Introduction

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

Prototype

public File getBasedir() 

Source Link

Usage

From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalTargetPlatformResolver.java

License:Open Source License

public ArtifactKey getArtifactKey(MavenSession session, MavenProject project) {
    OsgiManifest mf;// w  ww .j av  a  2s  .co m
    try {
        mf = manifestReader.loadManifest(project.getBasedir());
    } catch (OsgiManifestParserException e) {
        return null;
    }
    return DefaultArtifactKey.fromManifest(mf);
}

From source file:org.eclipse.tycho.core.osgitools.UpdateSiteProject.java

License:Open Source License

private UpdateSite loadSite(MavenProject project) {
    File file = new File(project.getBasedir(), UpdateSite.SITE_XML);
    try {//from  ww w.ja  v  a  2s.c  om
        return UpdateSite.read(file);
    } catch (IOException e) {
        throw new RuntimeException("Could not read site.xml " + file.getAbsolutePath(), e);
    }
}

From source file:org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader.java

License:Open Source License

private void setTarget(TargetPlatformConfiguration result, MavenSession session, MavenProject project,
        Xpp3Dom configuration) {// w  ww. j a  va2 s .  c o m
    Xpp3Dom targetDom = configuration.getChild("target");
    if (targetDom == null) {
        return;
    }

    Xpp3Dom artifactDom = targetDom.getChild("artifact");
    if (artifactDom == null) {
        return;
    }

    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
        return;
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");

    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;

    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
        if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId())
                && version.equals(otherProject.getVersion())) {
            targetFile = new File(otherProject.getBasedir(), classifier + ".target");
            break;
        }
    }

    if (targetFile == null) {
        Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version,
                "target", classifier);
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(project.getRemoteArtifactRepositories());
        repositorySystem.resolve(request);

        if (!artifact.isResolved()) {
            throw new RuntimeException("Could not resolve target platform specification artifact " + artifact);
        }

        targetFile = artifact.getFile();
    }

    result.setTarget(targetFile);
}

From source file:org.eclipse.tycho.core.utils.MavenSessionUtils.java

License:Open Source License

public static MavenProject getMavenProject(MavenSession session, File basedir) {
    for (MavenProject project : session.getProjects()) {
        if (basedir.equals(project.getBasedir())) {
            return project;
        }// www  .  j a  v a2 s  .  c o m
    }

    return null; // not a reactor project
}

From source file:org.eclipse.tycho.core.utils.MavenSessionUtils.java

License:Open Source License

public static Map<File, MavenProject> getBasedirMap(List<MavenProject> projects) {
    HashMap<File, MavenProject> result = new HashMap<File, MavenProject>();

    for (MavenProject project : projects) {
        result.put(project.getBasedir(), project);
    }//from www.  j a v  a 2 s .  co m

    return result;
}

From source file:org.eclipse.tycho.extras.buildtimestamp.jgit.JGitBuildTimestampProvider.java

License:Open Source License

public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution)
        throws MojoExecutionException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder() //
            .readEnvironment() //
            .findGitDir(project.getBasedir()) //
            .setMustExist(true);//  ww  w .j a  v a2s  .  c om
    try {
        Repository repository = builder.build();
        try {
            RevWalk walk = new RevWalk(repository);
            try {
                String relPath = getRelPath(repository, project);
                if (relPath != null && relPath.length() > 0) {
                    walk.setTreeFilter(AndTreeFilter.create(new PathFilter(relPath, getIgnoreFilter(execution)),
                            TreeFilter.ANY_DIFF));
                }

                // TODO make sure working tree is clean

                ObjectId headId = repository.resolve(Constants.HEAD);
                walk.markStart(walk.parseCommit(headId));
                RevCommit commit = walk.next();
                return new Date(commit.getCommitTime() * 1000L);
            } finally {
                walk.release();
            }
        } finally {
            repository.close();
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Could not determine git commit timestamp", e);
    }
}

From source file:org.eclipse.tycho.extras.buildtimestamp.jgit.JGitBuildTimestampProvider.java

License:Open Source License

private String getRelPath(Repository repository, MavenProject project) throws IOException {
    String workTree = repository.getWorkTree().getAbsolutePath();

    String path = project.getBasedir().getAbsolutePath();

    if (!path.startsWith(workTree)) {
        throw new IOException(project + " is not in git repository working tree " + repository.getWorkTree());
    }//from   w  w w  . j a v  a  2  s  .  c  om

    path = path.substring(workTree.length());

    if (path.startsWith("/")) {
        path = path.substring(1);
    }

    return path;
}

From source file:org.eclipse.tycho.extras.buildtimestamp.svn.SvnBuildTimestampProvider.java

License:Open Source License

public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution)
        throws MojoExecutionException {
    SVNClientManager clientManager = SVNClientManager.newInstance();
    SVNWCClient wcClient = clientManager.getWCClient();
    String ignoreFilter = getIgnoreFilter(execution);
    final Date[] result = { null };
    final Set<String> filterFiles = new HashSet<String>();

    if (ignoreFilter != null) {
        StringTokenizer tokens = new StringTokenizer(ignoreFilter, "\n\r\f");
        while (tokens.hasMoreTokens()) {
            filterFiles.add(tokens.nextToken());
        }/*w w w.j av  a2 s.c  om*/
    }

    try {
        wcClient.doInfo(project.getBasedir(), null, null, SVNDepth.INFINITY, null, new ISVNInfoHandler() {
            public void handleInfo(SVNInfo info) throws SVNException {
                File file = info.getFile();
                if (filterFiles.contains(file.getName())) {
                    return;
                }
                Date date = info.getCommittedDate();
                if (result[0] == null || date.after(result[0])) {
                    result[0] = date;
                }
            }
        });
    } catch (SVNException e) {
        throw new MojoExecutionException("Failed to get info", e);
    }

    return result[0];
}

From source file:org.eclipse.tycho.extras.sourcefeature.SourceFeatureP2MetadataProvider.java

License:Open Source License

public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession session, MavenProject project,
        List<Map<String, String>> environments, OptionalResolutionAction optionalAction) {
    File template = new File(project.getBasedir(), SourceFeatureMojo.FEATURE_TEMPLATE_DIR);

    if (!ArtifactKey.TYPE_ECLIPSE_FEATURE.equals(project.getPackaging()) || !template.isDirectory()) {
        return null;
    }//from   www  .  j  a va 2 s .c  o m

    Plugin plugin = project.getPlugin("org.eclipse.tycho.extras:tycho-source-feature-plugin");
    if (plugin != null) {
        try {
            File sourceFeatureBasedir = SourceFeatureMojo.getSourcesFeatureDir(project);

            /*
             * There is no easy way to determine what *exact* source bundles/features will be
             * included in the source feature at this point. Because of this, the source feature
             * dependency-only metadata does not include any dependencies.
             * 
             * This has two implications.
             * 
             * First, any missing source bundles/features will not be detected/reported until
             * source feature mojo is executed. This is inconsistent with how everything else
             * works in Tycho, but probably is a good thing.
             * 
             * More importantly, though, source bundles/features are not included as transitive
             * dependencies of other reactor projects that include the source feature. To solve
             * this for eclipse-repository project, repository project dependencies are
             * recalculated during repository packaging. Other 'aggregating' project types, like
             * eclipse-update-site and eclipse-feature with deployableFeature=true, will not be
             * compatible with source features until
             * https://bugs.eclipse.org/bugs/show_bug.cgi?id=353889 is implemented.
             */
            Feature feature = Feature.read(new File(project.getBasedir(), "feature.xml"));

            Document document = new Document();
            document.setRootNode(new Element("feature"));
            document.setXmlDeclaration(new XMLDeclaration("1.0", "UTF-8"));
            Feature sourceFeature = new Feature(document);

            sourceFeature.setId(feature.getId() + ".source");
            sourceFeature.setVersion(feature.getVersion());

            Feature.write(sourceFeature, new File(sourceFeatureBasedir, Feature.FEATURE_XML));

            String classifier = SourceFeatureMojo.SOURCES_FEATURE_CLASSIFIER;
            IArtifactFacade artifact = new AttachedArtifact(project, sourceFeatureBasedir, classifier);
            return Collections.singletonMap(classifier,
                    generator.generateMetadata(artifact, null, OptionalResolutionAction.REQUIRE));
        } catch (IOException e) {
            log.error("Could not create sources feature.xml", e);
        }
    }

    return null;
}

From source file:org.eclipse.tycho.extras.sourceref.jgit.JGitSourceReferencesProvider.java

License:Open Source License

public String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl) throws MojoExecutionException {
    File basedir = project.getBasedir().getAbsoluteFile();
    FileRepositoryBuilder builder = new FileRepositoryBuilder().readEnvironment().findGitDir(basedir)
            .setMustExist(true);// w w w  . j  a  va  2 s .com
    Repository repo;
    Git git;
    try {
        repo = builder.build();
        git = Git.wrap(repo);
    } catch (IOException e) {
        throw new MojoExecutionException("IO exception trying to create git repo ", e);
    }
    ObjectId head = resolveHead(repo);

    StringBuilder result = new StringBuilder(scmUrl.getUrl());
    result.append(";path=\"");
    result.append(getRelativePath(basedir, repo.getWorkTree()));
    result.append("\"");

    String tag = findTagForHead(git, head);
    if (tag != null) {
        // may contain e.g. spaces, so we quote it
        result.append(";tag=\"");
        result.append(tag);
        result.append("\"");
    }
    result.append(";commitId=");
    result.append(head.getName());
    return result.toString();
}