Search in sources :

Example 81 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ReleaseAction method selectionChanged.

/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
public void selectionChanged(IAction action, ISelection selection) {
    IFile[] locations = getLocations(selection);
    bndFiles = new LinkedHashMap<Project, List<File>>();
    for (IFile iFile : locations) {
        File file = iFile.getLocation().toFile();
        Project project;
        try {
            IProject iProject = iFile.getProject();
            project = Central.getWorkspace().getProject(iProject.getName());
            // .bnd files exists in cnf that are unreleasable
            if (project == null || project.isCnf()) {
                continue;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        List<File> projectFiles = bndFiles.get(project);
        if (projectFiles == null) {
            projectFiles = new ArrayList<File>();
            bndFiles.put(project, projectFiles);
        }
        projectFiles.add(file);
    }
}
Also used : Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject)

Example 82 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class WorkspaceAnalyserJob method getBuildOrder.

private static List<Project> getBuildOrder(IProgressMonitor monitor, Workspace workspace) throws Exception {
    List<Project> outlist = new ArrayList<Project>();
    monitor.setTaskName(Messages.calculatingBuildPath);
    for (Project project : workspace.getAllProjects()) {
        monitor.subTask(String.format(Messages.resolvingDependenciesForProject, project.getName()));
        Collection<Project> dependsOn = project.getDependson();
        getBuildOrder(dependsOn, outlist);
        if (!outlist.contains(project)) {
            outlist.add(project);
        }
        monitor.worked(1);
    }
    return outlist;
}
Also used : Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) ArrayList(java.util.ArrayList)

Example 83 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ExportPatternsListPart method getProject.

Project getProject() {
    Project project = null;
    try {
        BndEditModel model = (BndEditModel) getManagedForm().getInput();
        File bndFile = model.getBndResource();
        IPath path = Central.toPath(bndFile);
        IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        project = Central.getProject(resource.getProject());
    } catch (Exception e) {
        logger.logError("Error getting project from editor model", e);
    }
    return project;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) BndEditModel(aQute.bnd.build.model.BndEditModel) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 84 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ExportPatternsListPart method findSourcePackagesWithoutPackageInfo.

private Collection<FileVersionTuple> findSourcePackagesWithoutPackageInfo(Collection<? extends ExportedPackage> pkgs) throws Exception {
    Map<String, FileVersionTuple> result = new HashMap<String, FileVersionTuple>();
    Project project = getProject();
    if (project != null) {
        Collection<File> sourceDirs = project.getSourcePath();
        for (File sourceDir : sourceDirs) {
            for (ExportedPackage pkg : pkgs) {
                if (!result.containsKey(pkg.getName())) {
                    File pkgDir = new File(sourceDir, pkg.getName().replace('.', '/'));
                    if (pkgDir.isDirectory()) {
                        PackageInfoStyle existingPkgInfo = PackageInfoStyle.findExisting(pkgDir);
                        if (existingPkgInfo == null)
                            result.put(pkg.getName(), new FileVersionTuple(pkg.getName(), pkgDir));
                    }
                }
            }
        }
    }
    return result.values();
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) FileVersionTuple(bndtools.editor.contents.PackageInfoDialog.FileVersionTuple) HashMap(java.util.HashMap) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) PackageInfoStyle(bndtools.editor.contents.PackageInfoStyle) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 85 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ResolutionWizard method performFinish.

@Override
public boolean performFinish() {
    Collection<Resource> resources;
    ResolutionResult result = resultsPage.getResult();
    if (result != null && result.getOutcome() == ResolutionResult.Outcome.Resolved)
        resources = result.getResourceWirings().keySet();
    else
        resources = Collections.emptyList();
    // Open stream for physical paths list in target dir
    PrintStream pathsStream = null;
    try {
        File targetDir;
        Project bndProject = model.getProject();
        targetDir = bndProject.getTargetDir();
        if (targetDir == null)
            targetDir = file.getLocation().toFile().getParentFile();
        if (!targetDir.exists() && !targetDir.mkdirs()) {
            throw new IOException("Could not create target directory " + targetDir);
        }
        File pathsFile = new File(targetDir, file.getName() + RESOLVED_PATHS_EXTENSION);
        pathsStream = new PrintStream(pathsFile, "UTF-8");
    } catch (Exception e) {
        logger.logError("Unable to write resolved path list in target directory for project " + file.getProject().getName(), e);
    }
    // Generate -runbundles and path list
    try {
        List<VersionedClause> runBundles = new ArrayList<VersionedClause>(resources.size());
        for (Resource resource : resources) {
            VersionedClause runBundle = resourceToRunBundle(resource);
            //[cs] Skip dups
            if (runBundles.contains(runBundle)) {
                continue;
            }
            runBundles.add(runBundle);
            if (pathsStream != null) {
                VersionedClause runBundleWithUri = runBundle.clone();
                URI uri = ResourceUtils.getURI(ResourceUtils.getContentCapability(resource));
                runBundleWithUri.getAttribs().put(BndConstants.RESOLUTION_URI_ATTRIBUTE, uri.toString());
                StringBuilder builder = new StringBuilder();
                runBundleWithUri.formatTo(builder, clauseAttributeSorter);
                pathsStream.println(builder.toString());
            }
        }
        Collections.sort(runBundles, new Comparator<VersionedClause>() {

            @Override
            public int compare(VersionedClause vc1, VersionedClause vc2) {
                int diff = vc1.getName().compareTo(vc2.getName());
                if (diff != 0)
                    return diff;
                String r1 = vc1.getVersionRange();
                if (r1 == null)
                    r1 = "";
                String r2 = vc2.getVersionRange();
                if (r2 == null)
                    r2 = "";
                return r1.compareTo(r2);
            }
        });
        // Do not change the order of existing runbundles because they migh have been ordered manually
        List<VersionedClause> diffAddBundles = new ArrayList<>(runBundles);
        List<VersionedClause> oldRunBundles = model.getRunBundles();
        if (oldRunBundles == null)
            oldRunBundles = Collections.emptyList();
        else
            diffAddBundles.removeAll(oldRunBundles);
        List<VersionedClause> diffRemvedBundles = new ArrayList<>(oldRunBundles);
        diffRemvedBundles.removeAll(runBundles);
        List<VersionedClause> updatedRunBundles = new ArrayList<>(oldRunBundles);
        updatedRunBundles.addAll(diffAddBundles);
        updatedRunBundles.removeAll(diffRemvedBundles);
        // do not use getRunBundles().addAll, because it will not reflect in UI or File
        model.setRunBundles(updatedRunBundles);
    } finally {
        if (pathsStream != null) {
            IO.close(pathsStream);
        }
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) Project(aQute.bnd.build.Project) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

Project (aQute.bnd.build.Project)140 Workspace (aQute.bnd.build.Workspace)70 File (java.io.File)45 ArrayList (java.util.ArrayList)22 IProject (org.eclipse.core.resources.IProject)21 Container (aQute.bnd.build.Container)19 IOException (java.io.IOException)17 ProjectLauncher (aQute.bnd.build.ProjectLauncher)15 Version (aQute.bnd.version.Version)12 Description (aQute.lib.getopt.Description)12 Jar (aQute.bnd.osgi.Jar)11 Builder (aQute.bnd.osgi.Builder)10 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)9 Run (aQute.bnd.build.Run)8 BuildException (org.apache.tools.ant.BuildException)8 CoreException (org.eclipse.core.runtime.CoreException)8 IFile (org.eclipse.core.resources.IFile)7 ProjectBuilder (aQute.bnd.build.ProjectBuilder)6 ProjectTester (aQute.bnd.build.ProjectTester)5