Search in sources :

Example 1 with VersionControlIgnoresManager

use of org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager in project bndtools by bndtools.

the class VersionControlIgnoresManagerTracker method addingService.

/*
     * ServiceTracker
     */
@Override
public VersionControlIgnoresManager addingService(ServiceReference<VersionControlIgnoresManager> reference) {
    VersionControlIgnoresManager manager = super.addingService(reference);
    this.managerReference.set(reference);
    this.manager.set(manager);
    return manager;
}
Also used : VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager)

Example 2 with VersionControlIgnoresManager

use of org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager in project bndtools by bndtools.

the class GradleHeadlessBuildPlugin method setup.

@Override
public void setup(boolean cnf, File projectDir, boolean add, Set<String> enabledIgnorePlugins, List<String> warnings) throws IOException {
    if (!cnf) {
        return;
    }
    /* cnf */
    File workspaceRoot = projectDir.getParentFile();
    String baseDir = "templates/root/";
    copier.addOrRemoveDirectory(workspaceRoot, baseDir, "/", add ? CopyMode.ADD : CopyMode.REMOVE);
    Collection<File> files = copier.addOrRemoveDirectory(projectDir, baseDir, "/", add ? CopyMode.ADD : CopyMode.CHECK);
    for (File file : files) {
        String warning;
        if (add)
            warning = String.format("Not overwriting existing Gradle build file: %s", file);
        else
            warning = String.format("Gradle build file may need to be removed: %s", file);
        warnings.add(warning);
    }
    VersionControlIgnoresManager ignoresManager = versionControlIgnoresManager.get();
    if (ignoresManager != null) {
        List<String> ignoredEntries = new LinkedList<String>();
        ignoredEntries.add(ignoresManager.sanitiseGitIgnoreGlob(true, "/.gradle/", true));
        ignoredEntries.add(ignoresManager.sanitiseGitIgnoreGlob(true, "/reports/", true));
        ignoredEntries.add(ignoresManager.sanitiseGitIgnoreGlob(true, Workspace.getDefaults().getProperty(Constants.DEFAULT_PROP_TARGET_DIR), true));
        ignoresManager.addIgnores(enabledIgnorePlugins, workspaceRoot, ignoredEntries);
    }
}
Also used : VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager) File(java.io.File) LinkedList(java.util.LinkedList)

Example 3 with VersionControlIgnoresManager

use of org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager in project bndtools by bndtools.

the class AbstractNewBndProjectWizard method processGeneratedProject.

/**
     * Modify the newly generated Java project; this method is executed from within a workspace operation so is free to
     * make workspace resource modifications.
     *
     * @throws CoreException
     */
protected void processGeneratedProject(ProjectPaths projectPaths, BndEditModel bndModel, IJavaProject project, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 3);
    Document document = new Document("");
    bndModel.saveChangesTo(document);
    progress.worked(1);
    ByteArrayInputStream bndInput;
    try {
        bndInput = new ByteArrayInputStream(document.get().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return;
    }
    IFile bndBndFile = project.getProject().getFile(Project.BNDFILE);
    if (bndBndFile.exists()) {
        bndBndFile.setContents(bndInput, false, false, progress.newChild(1));
    }
    BndProject proj = generateBndProject(project.getProject(), progress.newChild(1));
    progress.setWorkRemaining(proj.getResources().size());
    for (Map.Entry<String, BndProjectResource> resource : proj.getResources().entrySet()) {
        importResource(project.getProject(), resource.getKey(), resource.getValue(), progress.newChild(1));
    }
    if (!bndBndFile.exists()) {
        bndBndFile.create(bndInput, false, progress.newChild(1));
    }
    /* Version control ignores */
    VersionControlIgnoresManager versionControlIgnoresManager = Plugin.getDefault().getVersionControlIgnoresManager();
    Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresManager, project, null);
    Map<String, String> sourceOutputLocations = JavaProjectUtils.getSourceOutputLocations(project);
    versionControlIgnoresManager.createProjectIgnores(enabledIgnorePlugins, project.getProject().getLocation().toFile(), sourceOutputLocations, projectPaths.getTargetDir());
    /* Headless build files */
    HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
    Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
    headlessBuildManager.setup(enabledPlugins, false, project.getProject().getLocation().toFile(), true, enabledIgnorePlugins, new LinkedList<String>());
    /* refresh the project; files were created outside of Eclipse API */
    project.getProject().refreshLocal(IResource.DEPTH_INFINITE, progress);
    project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, progress);
}
Also used : IFile(org.eclipse.core.resources.IFile) BndPreferences(bndtools.preferences.BndPreferences) VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager) HeadlessBuildManager(org.bndtools.headless.build.manager.api.HeadlessBuildManager) SubMonitor(org.eclipse.core.runtime.SubMonitor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Document(aQute.bnd.properties.Document) BndProject(bndtools.editor.model.BndProject) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) BndProjectResource(org.bndtools.api.BndProjectResource)

Example 4 with VersionControlIgnoresManager

use of org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager in project bndtools by bndtools.

the class ToggleNatureAction method toggleNature.

/**
     * Toggles sample nature on a project
     *
     * @param project
     *            to have sample nature added or removed
     */
private static IStatus toggleNature(IJavaProject project) {
    try {
        /* Version control ignores */
        VersionControlIgnoresManager versionControlIgnoresManager = Plugin.getDefault().getVersionControlIgnoresManager();
        Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresManager, project, null);
        /* Headless build files */
        HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
        Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
        IProject iProject = project.getProject();
        IProjectDescription description = iProject.getDescription();
        String[] natures = description.getNatureIds();
        List<String> headlessBuildWarnings = new LinkedList<>();
        for (int i = 0; i < natures.length; ++i) {
            if (BndtoolsConstants.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                iProject.setDescription(description, null);
                /* Remove the headless build files */
                headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), false, enabledIgnorePlugins, headlessBuildWarnings);
                /* refresh the project; files were created outside of Eclipse API */
                iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
                return createStatus("Obsolete build files may remain in the project. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
            }
        }
        /* Add the headless build files */
        headlessBuildManager.setup(enabledPlugins, false, iProject.getLocation().toFile(), true, enabledIgnorePlugins, headlessBuildWarnings);
        // Add the nature
        ensureBndBndExists(iProject);
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = BndtoolsConstants.NATURE_ID;
        description.setNatureIds(newNatures);
        iProject.setDescription(description, null);
        /* refresh the project; files were created outside of Eclipse API */
        iProject.refreshLocal(IResource.DEPTH_INFINITE, null);
        return createStatus("Some build files could not be generated. Please review the messages below.", Collections.<String>emptyList(), headlessBuildWarnings);
    } catch (CoreException e) {
        return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error occurred while toggling Bnd project nature", e);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BndPreferences(bndtools.preferences.BndPreferences) VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager) HeadlessBuildManager(org.bndtools.headless.build.manager.api.HeadlessBuildManager) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 5 with VersionControlIgnoresManager

use of org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager in project bndtools by bndtools.

the class VersionControlIgnoresManagerTracker method addIgnores.

@Override
public void addIgnores(Set<String> plugins, File dstDir, List<String> ignores) {
    VersionControlIgnoresManager manager = this.manager.get();
    if (manager == null) {
        return;
    }
    manager.addIgnores(plugins, dstDir, ignores);
}
Also used : VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager)

Aggregations

VersionControlIgnoresManager (org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager)7 BndPreferences (bndtools.preferences.BndPreferences)2 LinkedList (java.util.LinkedList)2 HeadlessBuildManager (org.bndtools.headless.build.manager.api.HeadlessBuildManager)2 Document (aQute.bnd.properties.Document)1 BndProject (bndtools.editor.model.BndProject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1 BndProjectResource (org.bndtools.api.BndProjectResource)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1