use of aQute.bnd.osgi.Instruction 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);
}
}
}
use of aQute.bnd.osgi.Instruction in project bnd by bndtools.
the class FileRepo method list.
public List<String> list(String regex) throws Exception {
init();
Instruction pattern = null;
if (regex != null)
pattern = new Instruction(regex);
List<String> result = new ArrayList<String>();
if (root == null) {
if (reporter != null)
reporter.error("FileRepo root directory is not set.");
} else {
File[] list = root.listFiles();
if (list != null) {
for (File f : list) {
if (!f.isDirectory())
// ignore non-directories
continue;
String fileName = f.getName();
if (fileName.charAt(0) == '.')
// ignore hidden files
continue;
if (pattern == null || pattern.matches(fileName))
result.add(fileName);
}
} else if (reporter != null)
reporter.error("FileRepo root directory (%s) does not exist", root);
}
return result;
}
use of aQute.bnd.osgi.Instruction in project bnd by bndtools.
the class DSAnnotations method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.DSANNOTATIONS, "*"));
if (header.size() == 0)
return false;
minVersion = AnnotationReader.V1_3;
Parameters optionsHeader = OSGiHeader.parseHeader(analyzer.mergeProperties(Constants.DSANNOTATIONS_OPTIONS));
EnumSet<Options> options = EnumSet.noneOf(Options.class);
for (Map.Entry<String, Attrs> entry : optionsHeader.entrySet()) {
try {
Options.parseOption(entry, options, this);
} catch (IllegalArgumentException e) {
analyzer.error("Unrecognized %s value %s with attributes %s, expected values are %s", Constants.DSANNOTATIONS_OPTIONS, entry.getKey(), entry.getValue(), EnumSet.allOf(Options.class));
}
}
// obsolete but backwards compatible, use the options instead
if (Processor.isTrue(analyzer.getProperty("-dsannotations-inherit")))
options.add(Options.inherit);
if (Processor.isTrue(analyzer.getProperty("-ds-felix-extensions")))
options.add(Options.felixExtensions);
Instructions instructions = new Instructions(header);
Collection<Clazz> list = analyzer.getClassspace().values();
String sc = analyzer.getProperty(Constants.SERVICE_COMPONENT);
List<String> names = new ArrayList<String>();
if (sc != null && sc.trim().length() > 0)
names.add(sc);
TreeSet<String> provides = new TreeSet<String>();
TreeSet<String> requires = new TreeSet<String>();
Version maxVersion = AnnotationReader.V1_0;
XMLAttributeFinder finder = new XMLAttributeFinder(analyzer);
boolean componentProcessed = false;
for (Clazz c : list) {
for (Instruction instruction : instructions.keySet()) {
if (instruction.matches(c.getFQN())) {
if (instruction.isNegated())
break;
ComponentDef definition = AnnotationReader.getDefinition(c, analyzer, options, finder, minVersion);
if (definition != null) {
componentProcessed = true;
definition.sortReferences();
definition.prepare(analyzer);
String name = "OSGI-INF/" + analyzer.validResourcePath(definition.name, "Invalid component name") + ".xml";
names.add(name);
analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
if (definition.service != null && !options.contains(Options.nocapabilities)) {
String[] objectClass = new String[definition.service.length];
for (int i = 0; i < definition.service.length; i++) {
Descriptors.TypeRef tr = definition.service[i];
objectClass[i] = tr.getFQN();
}
Arrays.sort(objectClass);
addServiceCapability(objectClass, provides);
}
if (!options.contains(Options.norequirements)) {
MergedRequirement serviceReqMerge = new MergedRequirement("osgi.service");
for (ReferenceDef ref : definition.references.values()) {
addServiceRequirement(ref, serviceReqMerge);
}
requires.addAll(serviceReqMerge.toStringList());
}
maxVersion = ComponentDef.max(maxVersion, definition.version);
}
}
}
}
if (componentProcessed && (options.contains(Options.extender) || (maxVersion.compareTo(AnnotationReader.V1_3) >= 0))) {
maxVersion = ComponentDef.max(maxVersion, AnnotationReader.V1_3);
addExtenderRequirement(requires, maxVersion);
}
sc = Processor.append(names.toArray(new String[0]));
analyzer.setProperty(Constants.SERVICE_COMPONENT, sc);
updateHeader(analyzer, Constants.REQUIRE_CAPABILITY, requires);
updateHeader(analyzer, Constants.PROVIDE_CAPABILITY, provides);
return false;
}
Aggregations