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.sourcepit.tpmp.b2.B2Utils.java

License:Apache License

public static boolean isDerivedProject(MavenProject project) {
    File parentFile = project.getBasedir().getParentFile();
    while (parentFile != null) {
        if (".b2".equals(parentFile.getName())) {
            return true;
        }//from   ww  w . j ava2s  . c o  m
        parentFile = parentFile.getParentFile();
    }
    return false;
}

From source file:org.sourcepit.tpmp.change.b2.B2TargetPlatformConfigurationFilesDiscoverer.java

License:Apache License

@Override
public List<File> getTargetPlatformConfigurationFiles(MavenSession session, MavenProject project) {
    final List<File> files = new ArrayList<File>();

    final File moduleXML = B2Utils.findModuleXML(session, project);
    if (moduleXML != null) {
        final File modulePom = new File(moduleXML.getParentFile(), ".b2/module-pom-template.xml");
        if (modulePom.exists()) {
            files.add(modulePom);/*  w w w.j av a2 s. com*/

            if (!B2Utils.isDerivedProject(project)) {
                final File b2ExtFile = new File(project.getBasedir(), "b2-extension.xml");
                if (b2ExtFile.exists()) {
                    files.add(b2ExtFile);
                }

                files.addAll(super.getTargetPlatformConfigurationFiles(session, project));
                files.remove(project.getFile());
            }
            return files;
        }
    }

    throw new IllegalStateException();
}

From source file:org.sourcepit.tpmp.change.tycho.TychoTargetPlatformConfigurationFilesDiscoverer.java

License:Apache License

@Override
public List<File> getTargetPlatformConfigurationFiles(MavenSession session, MavenProject project) {
    final List<File> files = new ArrayList<File>();
    files.add(project.getFile());//from w  w  w  .  j  av a 2  s .  co m

    final TychoProject tychoProject = projectTypes.get(project.getPackaging());
    if (tychoProject != null) {
        if (tychoProject instanceof OsgiBundleProject) {
            files.add(new File(project.getBasedir(), "META-INF/MANIFEST.MF"));
        } else if (tychoProject instanceof EclipseApplicationProject) {
            files.add(new File(project.getBasedir(), project.getArtifactId() + ".product"));
        } else if (tychoProject instanceof EclipseFeatureProject) {
            files.add(new File(project.getBasedir(), Feature.FEATURE_XML));
        } else if (tychoProject instanceof EclipseRepositoryProject) {
            files.addAll(/* ((EclipseRepositoryProject) tychoProject). */getCategoryFiles(project));
            files.addAll(((EclipseRepositoryProject) tychoProject).getProductFiles(project));
        } else if (tychoProject instanceof UpdateSiteProject) {
            files.add(new File(project.getBasedir(), UpdateSite.SITE_XML));
        }
    }

    return files;
}

From source file:org.sourcepit.tpmp.resolver.tycho.AbstractTychoTargetPlatformResolver.java

License:Apache License

private void handlePluginsAndFeatures(MavenSession session, MavenProject project,
        final DependencyArtifacts platformArtifacts, final Set<String> explodedBundles,
        TargetPlatformResolutionHandler resolutionHandler) {
    // map original rector projects to their versioned id. needed to recognize and re-map reactor artifacts later
    final Map<String, MavenProject> vidToProjectMap = projectFacade.createVidToProjectMap(session);

    for (ArtifactDescriptor artifact : platformArtifacts.getArtifacts(PackagingType.TYPE_ECLIPSE_FEATURE)) {
        final Optional<MavenProject> mavenProject = projectFacade.getMavenProject(vidToProjectMap, artifact);

        final File location = projectFacade.getLocation(artifact, mavenProject);

        if (project.getBasedir().equals(location)) {
            continue;
        }// www  . j a va2  s. c om

        // due to the feature model of Tycho violates the specified behaviour of the "unpack" attribute, we have to
        // parse the feature.xml on our own. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=386851.
        final Document feature = loadFeature(location);
        for (Node pluginNode : XmlUtils.queryNodes(feature, "/feature/plugin")) {
            final Element plugin = (Element) pluginNode;
            if (isUnpack(plugin)) {
                explodedBundles.add(getId(plugin));
            }
        }

        final ArtifactKey key = projectFacade.getArtifactKey(artifact, mavenProject);
        resolutionHandler.handleFeature(key.getId(), key.getVersion(), location, mavenProject.orNull());
    }

    for (ArtifactDescriptor artifact : platformArtifacts.getArtifacts()) {
        // Pre Tycho 0.20.0 source artifacts was typed as "eclipse-repository"... Now source artifacts are
        // eclipse-plugins. Because of we will resolve sources later, ignore it here.
        if (!"sources".equals(artifact.getClassifier())) {
            final Optional<MavenProject> mavenProject = projectFacade.getMavenProject(vidToProjectMap,
                    artifact);
            final File location = projectFacade.getLocation(artifact, mavenProject);
            if (project.getBasedir().equals(location)) {
                continue;
            }

            final ArtifactKey key = projectFacade.getArtifactKey(artifact, mavenProject);
            final String type = key.getType();
            if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(type)
                    || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(type)) {
                final boolean explodedBundle = isExplodedBundle(key.getId(), location, explodedBundles);
                resolutionHandler.handlePlugin(key.getId(), key.getVersion(), location, explodedBundle,
                        mavenProject.orNull());
            }
        }
    }
}

From source file:org.springframework.ide.eclipse.maven.legacy.internal.core.GoogleProjectConfigurator.java

License:Open Source License

/**
 * {@inheritDoc}//from ww  w .  j  a v a  2s  . c om
 */
@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    configureNature(project, mavenProject, GAE_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {
            try {
                DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                executionRequest.setBaseDirectory(mavenProject.getBasedir());
                executionRequest.setLocalRepository(maven.getLocalRepository());
                executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                executionRequest.setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                executionRequest.setPom(mavenProject.getFile());
                executionRequest.setGoals(GAE_UNPACK_GOAL);

                MavenExecutionResult result = maven.execute(executionRequest, monitor);
                if (result.hasExceptions()) {
                    MavenCorePlugin.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, MavenCorePlugin.NON_LEGACY_PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                }
            } catch (CoreException e) {
                MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                        MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
            }
        }
    }, monitor);

    if (configureNature(project, mavenProject, GWT_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {

            // Get the GWT version from the project pom
            String gwtVersion = null;
            List<Dependency> dependencies = mavenProject.getDependencies();
            for (Dependency dependency : dependencies) {
                if (GWT_GROUP_ID.equals(dependency.getGroupId())
                        && ("gwt-user".equals(dependency.getArtifactId())
                                || "gwt-servlet".equals(dependency.getArtifactId()))) {
                    gwtVersion = dependency.getVersion();
                    break;
                }
            }

            // Check that the pom.xml has GWT dependencies
            if (StringUtils.hasLength(gwtVersion)) {
                try {
                    // Download and install the gwt-dev.jar into the local repository
                    maven.resolve(GWT_GROUP_ID, "gwt-dev", gwtVersion, "jar", null,
                            mavenProject.getRemoteArtifactRepositories(), monitor);
                } catch (CoreException e) {
                    MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                            MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
                }
            }
        }
    }, monitor)) {

        try {
            // Add GWT Web Application configuration parameters
            IEclipsePreferences prefs = SpringCorePreferences
                    .getProjectPreferences(project, "com.google.gdt.eclipse.core").getProjectPreferences();
            prefs.put("warSrcDir", "src/main/webapp");
            prefs.putBoolean("warSrcDirIsOutput", false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = SpringCoreUtils.getProjectLocation(project);
            if (location != null && artifactId != null && version != null) {
                prefs.put("lastWarOutDir", location.append("target").append(artifactId + "-" + version).toFile()
                        .getAbsolutePath());
            }

            prefs.flush();
        } catch (BackingStoreException e) {
            MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                    MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
        }
    }
}

From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java

License:Open Source License

public void interpolateModel(MavenProject project, Model model) throws MavenException {
    ModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setUserProperties(project.getProperties());
    ModelProblemCollector problems = new ModelProblemCollector() {
        @Override//  www. j  a  v a 2 s  .  c  o m
        public void add(ModelProblemCollectorRequest req) {
        }
    };
    lookup(ModelInterpolator.class).interpolateModel(model, project.getBasedir(), request, problems);
}

From source file:org.switchyard.tools.ui.M2EUtils.java

License:Open Source License

/**
 * Returns the generated switchyard.xml file. By default, this is
 * target/class/META-INF/switchyard.xml.
 * /*from w ww  .j  a v  a  2 s. co m*/
 * @param project the project
 * @return the location of the generated switchyard.xml file.
 */
public static File getSwitchYardOutputFile(MavenProject project) {
    if (project == null) {
        return null;
    }
    Plugin plugin = findSwitchYardPlugin(project.getModel());
    if (plugin == null) {
        return null;
    }
    Xpp3Dom configuration = findSwitchYardPluginConfiguration(plugin);
    if (configuration != null) {
        Xpp3Dom node = configuration.getChild("outputFile"); //$NON-NLS-1$
        if (node != null && node.getValue() != null) {
            return new File(project.getBasedir(), node.getValue());
        }
        node = configuration.getChild("outputDirectory"); //$NON-NLS-1$
        if (node != null && node.getValue() != null) {
            return new File(new File(project.getBasedir(), node.getValue()), "META-INF/switchyard.xml"); //$NON-NLS-1$
        }
    }
    return new File(project.getBuild().getOutputDirectory(), "META-INF/switchyard.xml"); //$NON-NLS-1$
}

From source file:org.universAAL.support.directives.checks.CodificationCheck.java

License:Apache License

/** {@ inheritDoc}    */
public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    SourceExplorer se = new SourceExplorer(this);
    ArrayList<File> conflicted = se.walk(mavenProject.getBasedir().getAbsolutePath() + "/src/main/java/");
    if (conflicted.size() > 0) {
        String m = "The following Files Contain a possibly charset coding error:\n";
        for (File file : conflicted) {
            m += "\t" + file.getAbsolutePath() + ":" + lineMap.get(file) + "\n";
        }/*  w w w .j  av  a  2 s.  co m*/
        m += "To solve this problem, make sure there are no charracters that can be code incompatible, or write everything in UTF-8.";
        throw new MojoFailureException(m);
    }
    return true;
}

From source file:org.universAAL.support.directives.checks.DecoupleCheck.java

License:Apache License

/** {@inheritDoc}  */
public boolean check(MavenProject mavenProject, Log log) throws MojoFailureException, MojoExecutionException {
    SourceExplorer se = new SourceExplorer(this);
    ArrayList<File> conflicted = se.walk(mavenProject.getBasedir() + "/src/main/java/");
    if (conflicted.size() > 0) {
        String m = "The following Files are not Container Decoupled:\n";
        for (java.util.Iterator<File> iterator = conflicted.iterator(); iterator.hasNext();) {
            m += "\t" + iterator.next().getAbsolutePath() + "\n";
        }/*from   w ww  .  j  a v  a  2s. c o m*/
        m += "To solve this problem, make sure there are no OSGi imports in your classes,"
                + " unless the package that contains them has explicitly \"osgi\" in it's name.";
        throw new MojoFailureException(m);
    }
    return true;
}

From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java

License:Apache License

public static List<MavenProject> getChildrenModules(MavenProject mavenProject, MavenProjectBuilder mpb,
        ArtifactRepository localRepository, ProfileManager pm) {
    List<MavenProject> children = new ArrayList<MavenProject>();
    List<String> modules = mavenProject.getModules();
    for (String mod : modules) {
        try {/*from  ww  w  . ja va 2s. c o m*/
            children.add(mpb.buildWithDependencies(new File(mavenProject.getBasedir(), mod + "/pom.xml"),
                    localRepository, pm));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return children;
}