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.universAAL.support.directives.checks.SVNCheck.java

License:Apache License

public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    this.mavenProject = mavenProject;
    log.debug("checking svn for " + mavenProject.getBasedir().getPath());
    try {/*  ww  w . ja va 2 s. com*/
        surl = getSVNURL(mavenProject.getBasedir());

        log.debug("found URL   : " + surl);
        log.debug("comparing with   : " + mavenProject.getScm().getConnection());
        log.debug("comparing with   : " + mavenProject.getScm().getDeveloperConnection());
        if (missMatchURLs(surl) || missMatchURLs(surl.replace(OLD_URL, NEW_URL))) {
            throw new MojoFailureException(SCM_NOT_CONFIGURED);

        } else {
            log.debug("SCM and SVN info are in sync.");
            return true;
        }
    } catch (SVNException e) {
        log.warn("SVN Error.", e);
        log.warn("directory seems not to be a local SVN working copy.");
        throw new MojoExecutionException("Directory seems not to be a local SVN working copy.", e);
    } catch (MojoFailureException e) {
        throw e;
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e1) {
        throw new MojoExecutionException("Unexpected Exception", e1);
    }
}

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

License:Apache License

/** {@inheritDoc} */
public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    this.log = log;
    SVNClientManager cli = SVNClientManager.newInstance();
    log.debug("checking svn ignore Rules in: " + mavenProject.getBasedir().getPath());
    try {/*from w ww  .  j  a va  2 s . c  o m*/
        wcCli = cli.getWCClient();
        SVNPropertyData pd = wcCli.doGetProperty(mavenProject.getBasedir(), SVNProperty.IGNORE,
                SVNRevision.WORKING, SVNRevision.WORKING);
        boolean changed = false;
        if (pd == null) {
            changed = true;
            prop = "";
            for (int i = 0; i < ignores.length; i++)
                prop += ignores[i] + "\n";
        } else {
            prop = pd.getValue().getString();
            log.debug("Ignore Property contains: " + prop);// .split("\n")[0]
            for (int i = 0; i < ignores.length; i++) {
                if (!prop.contains(ignores[i]) && exists(mavenProject, ignores[i])) {
                    prop += ignores[i] + "\n";
                    changed = true;
                }
            }
        }
        if (changed) {
            String err = NO_IGNORES;
            for (int i = 0; i < ignores.length; i++) {
                err += "\n\t" + ignores[i];
            }
            throw new MojoFailureException(err);
        }
    } catch (SVNException e) {
        e.printStackTrace();
        log.warn("SVN Error.");
        log.warn("directory seems not to be a local SVN working copy.");
        return false;
    }
    return true;
}

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

License:Apache License

private boolean exists(MavenProject mavenProject, String string) {
    String[] files = mavenProject.getBasedir().list();
    int i = 0;/*from   w w w  .  j  av a2 s  . c  o  m*/
    log.debug("Matching: " + string);
    while (i < files.length && !files[i].endsWith(string.replace("*", ""))) {
        log.debug("No Match: " + files[i] + " with " + string);
        i++;
    }
    if (i < files.length) {
        return files[i].endsWith(string.replace("*", ""));
    } else {
        return false;
    }
}

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

License:Apache License

/** {@inheritDoc} */
public void fix(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    SVNPropertyValue propValue = SVNPropertyValue.create(SVNProperty.IGNORE,
            prop.getBytes(Charset.defaultCharset()));
    Collection<String> cl = new ArrayList<String>();
    cl.add("added ignore list");
    try {/*  w  w  w  .  ja v a  2  s  . c  o  m*/
        wcCli.doSetProperty(mavenProject.getBasedir(), SVNProperty.IGNORE, propValue, false,
                SVNDepth.IMMEDIATES, null, cl);
    } catch (SVNException e) {
        throw new MojoExecutionException("error setting SVN properties.", e);
    }
    log.info("Fixing ignore list");
}

From source file:org.universAAL.support.directives.procedures.Tag.java

License:Apache License

/** {@inheritDoc} */
public void execute(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    if (baseURL == null) {
        baseURL = mavenProject.getScm().getDeveloperConnection();
    }//from w ww.  j  a v a  2  s.c  o  m
    String tagUrl = getTagURL(mavenProject);
    log.info("Tagging: " + baseURL + "  ->  " + tagUrl);
    if (tagRemoteHead) {
        if (!performTag(baseURL, tagUrl, "Automatic tag of " + mavenProject.getArtifactId() + " version: "
                + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    } else {
        if (!performWCTag(mavenProject.getBasedir(), tagUrl, "Automatic tag of " + mavenProject.getArtifactId()
                + " version: " + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    }
}

From source file:org.universaal.tools.buildserviceapplication.actions.CreateLaunchConfigurationFile.java

License:Apache License

public MavenProject getSelectedMavenProject() {
    for (int i = 0; i < BuildAction.buildedProjects.size(); i++) {
        MavenProject project = BuildAction.buildedProjects.get(i);
        if (project.getArtifactId().equals(BuildAction.getSelectedProjectName())
                && project.getBasedir().toString().equals(BuildAction.getSelectedProjectPath())) {
            return project;
        }/*  w w  w .  j av a 2s.  com*/
    }
    return null;
}

From source file:org.wisdom.maven.osgi.Classpath.java

License:Apache License

/**
 * Stores the dependencies from the given project into the 'dependencies.json' file.
 *
 * @param project the project//  ww  w.  j a  va  2  s.  co  m
 * @throws IOException if the file cannot be created.
 */
public static void store(MavenProject project) throws IOException {
    final File output = new File(project.getBasedir(), Constants.DEPENDENCIES_FILE);
    output.getParentFile().mkdirs();
    ProjectDependencies dependencies = new ProjectDependencies(project);
    mapper.writer().withDefaultPrettyPrinter().writeValue(output, dependencies);
}

From source file:org.wisdom.maven.utils.ApplicationSecretGenerator.java

License:Apache License

/**
 * Checks whether the application configuration file as the application secret.
 * If not generates one.//from   ww w  .  j  ava  2  s.  c  o  m
 *
 * @param project the Maven Project
 * @param log     the logger
 * @throws java.io.IOException if the application file cannot be read, or rewritten
 */
public static void ensureOrGenerateSecret(MavenProject project, Log log) throws IOException {
    File conf = new File(project.getBasedir(), "src/main/configuration/application.conf");
    if (conf.isFile()) {
        List<String> lines = FileUtils.readLines(conf);

        boolean changed = false;
        for (int i = 0; i < lines.size(); i++) {
            String line = lines.get(i);
            Matcher matcher = OLD_SECRET_LINE_PATTERN.matcher(line);
            if (matcher.matches()) {
                if (matcher.group(1).length() == 0) {
                    lines.set(i, "application.secret=\"" + generate() + "\"");
                    changed = true;
                }
            } else {
                matcher = SECRET_LINE_PATTERN.matcher(line);
                if (matcher.matches()) {
                    if (matcher.group(2).trim().length() == 0) {
                        lines.set(i, "  secret = \"" + generate() + "\"");
                        changed = true;
                    }
                }
            }

        }

        if (changed) {
            FileUtils.writeLines(conf, lines);
            log.info("Application Secret generated - the configuration file was updated.");
        }

    }
}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project/* ww  w.j  a v  a2  s.  co m*/
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:org.wso2.maven.p2.utils.ProductFileUtils.java

License:Open Source License

/**
 * Get path to dynamically generated product file.
 *
 * @param mavenProject              bean as read from project pom.
 * @return String                   Path to dynamically generated product file.
 * @throws MojoExecutionException   Is thrown if maven project is not been able to be read.
 *///  ww w.ja  v  a2 s .  c  o m
public static String getProductFilePath(MavenProject mavenProject) throws MojoExecutionException {
    if (mavenProject == null) {
        throw new MojoExecutionException("Unable to read maven project for finding project path.");
    } else {
        return mavenProject.getBasedir().getAbsolutePath() + File.separator
                + P2Constants.ProductFile.TARGET_DIRECTORY + File.separator + P2Constants.ProductFile.NAME;
    }
}