Search in sources :

Example 1 with DependencyContributor

use of aQute.bnd.service.DependencyContributor in project bnd by bndtools.

the class Project method prepare.

/**
	 * Set up all the paths
	 */
public void prepare() throws Exception {
    if (!isValid()) {
        warning("Invalid project attempts to prepare: %s", this);
        return;
    }
    synchronized (preparedPaths) {
        if (preparedPaths.get()) {
            return;
        }
        if (!workspace.trail.add(this)) {
            throw new CircularDependencyException(workspace.trail.toString() + "," + this);
        }
        try {
            String prefix = getBase().getAbsolutePath();
            dependson.clear();
            buildpath.clear();
            sourcepath.clear();
            allsourcepath.clear();
            bootclasspath.clear();
            // JIT
            testpath.clear();
            runpath.clear();
            runbundles.clear();
            runfw.clear();
            // We use a builder to construct all the properties for
            // use.
            setProperty("basedir", getBase().getAbsolutePath());
            // Otherwise, we just do the build properties.
            if (!getPropertiesFile().isFile() && new File(getBase(), ".classpath").isFile()) {
                // Get our Eclipse info, we might depend on other
                // projects
                // though ideally this should become empty and void
                doEclipseClasspath();
            }
            // Calculate our source directories
            Parameters srces = new Parameters(mergeProperties(Constants.DEFAULT_PROP_SRC_DIR), this);
            if (srces.isEmpty())
                srces.add(Constants.DEFAULT_PROP_SRC_DIR, new Attrs());
            for (Entry<String, Attrs> e : srces.entrySet()) {
                File dir = getFile(removeDuplicateMarker(e.getKey()));
                if (!dir.getAbsolutePath().startsWith(prefix)) {
                    error("The source directory lies outside the project %s directory: %s", this, dir).header(Constants.DEFAULT_PROP_SRC_DIR).context(e.getKey());
                    continue;
                }
                if (!dir.isDirectory()) {
                    IO.mkdirs(dir);
                }
                if (dir.isDirectory()) {
                    sourcepath.put(dir, new Attrs(e.getValue()));
                    allsourcepath.add(dir);
                } else
                    error("the src path (src property) contains an entry that is not a directory %s", dir).header(Constants.DEFAULT_PROP_SRC_DIR).context(e.getKey());
            }
            // Set default bin directory
            output = getSrcOutput().getAbsoluteFile();
            if (!output.exists()) {
                IO.mkdirs(output);
                getWorkspace().changedFile(output);
            }
            if (!output.isDirectory()) {
                msgs.NoOutputDirectory_(output);
            }
            // Where we store all our generated stuff.
            target = getTarget0();
            // Where the launched OSGi framework stores stuff
            String runStorageStr = getProperty(Constants.RUNSTORAGE);
            runstorage = runStorageStr != null ? getFile(runStorageStr) : null;
            // We might have some other projects we want build
            // before we do anything, but these projects are not in
            // our path. The -dependson allows you to build them before.
            // The values are possibly negated globbing patterns.
            // dependencies.add( getWorkspace().getProject("cnf"));
            Set<String> requiredProjectNames = new LinkedHashSet<String>(getMergedParameters(Constants.DEPENDSON).keySet());
            // Allow DependencyConstributors to modify requiredProjectNames
            List<DependencyContributor> dcs = getPlugins(DependencyContributor.class);
            for (DependencyContributor dc : dcs) dc.addDependencies(this, requiredProjectNames);
            Instructions is = new Instructions(requiredProjectNames);
            Set<Instruction> unused = new HashSet<Instruction>();
            Collection<Project> projects = getWorkspace().getAllProjects();
            Collection<Project> dependencies = is.select(projects, unused, false);
            for (Instruction u : unused) msgs.MissingDependson_(u.getInput());
            // We have two paths that consists of repo files, projects,
            // or some other stuff. The doPath routine adds them to the
            // path and extracts the projects so we can build them
            // before.
            doPath(buildpath, dependencies, parseBuildpath(), bootclasspath, false, BUILDPATH);
            doPath(testpath, dependencies, parseTestpath(), bootclasspath, false, TESTPATH);
            if (!delayRunDependencies) {
                doPath(runfw, dependencies, parseRunFw(), null, false, RUNFW);
                doPath(runpath, dependencies, parseRunpath(), null, false, RUNPATH);
                doPath(runbundles, dependencies, parseRunbundles(), null, true, RUNBUNDLES);
            }
            // We now know all dependent projects. But we also depend
            // on whatever those projects depend on. This creates an
            // ordered list without any duplicates. This of course assumes
            // that there is no circularity. However, this is checked
            // by the inPrepare flag, will throw an exception if we
            // are circular.
            Set<Project> done = new HashSet<Project>();
            done.add(this);
            for (Project project : dependencies) project.traverse(dependson, done);
            for (Project project : dependson) {
                allsourcepath.addAll(project.getSourcePath());
            }
            // [cs] Testing this commented out. If bad issues, never
            // setting this to true means that
            // TONS of extra preparing is done over and over again on
            // the same projects.
            // if (isOk())
            preparedPaths.set(true);
        } finally {
            workspace.trail.remove(this);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) DependencyContributor(aQute.bnd.service.DependencyContributor) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Attrs (aQute.bnd.header.Attrs)1 Parameters (aQute.bnd.header.Parameters)1 Instruction (aQute.bnd.osgi.Instruction)1 Instructions (aQute.bnd.osgi.Instructions)1 DependencyContributor (aQute.bnd.service.DependencyContributor)1 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1