예제 #1
0
  /** Check if the getSubBuilders properly predicts the output. */
  public static void testSubBuilders() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p4-sub");

    Collection<? extends Builder> bs = project.getSubBuilders();
    assertNotNull(bs);
    assertEquals(3, bs.size());
    Set<String> names = new HashSet<String>();
    for (Builder b : bs) {
      names.add(b.getBsn());
    }
    assertTrue(names.contains("p4-sub.a"));
    assertTrue(names.contains("p4-sub.b"));
    assertTrue(names.contains("p4-sub.c"));

    File[] files = project.build();
    assertTrue(project.check());

    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));
    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);
    for (File file : files) {
      Jar jar = new Jar(file);
      Manifest m = jar.getManifest();
      assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName")));
    }
  }
예제 #2
0
  public static void testBumpSubBuilders() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("bump-sub");
      project.setTrace(true);

      assertNull(project.getProperty("Bundle-Version"));

      project.bump("=+0");

      assertNull(project.getProperty("Bundle-Version"));

      for (Builder b : project.getSubBuilders()) {
        assertEquals(new Version(1, 1, 0), new Version(b.getVersion()));
      }
    } finally {
      IO.deleteWithException(tmp);
    }
  }
예제 #3
0
 /** The default policy is truncate micro. Check if this is applied to the import. */
 public static void testImportMicroTruncated() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.setProperty("Import-Package", "org.osgi.service.event");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("[1.0,2)", s);
 }
예제 #4
0
 public static Settings readSettingsFromStream(StreamInput in) throws IOException {
   Builder builder = new Builder();
   int numberOfSettings = in.readVInt();
   for (int i = 0; i < numberOfSettings; i++) {
     builder.put(in.readString(), in.readString());
   }
   return builder.build();
 }
예제 #5
0
 /** Check if we can set a specific version on the import that does not use a version policy. */
 public static void testImportMicroNotTruncated() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.setProperty(
       "Import-Package",
       "org.osgi.service.event;version=${@}, org.osgi.service.log;version=\"${range;[==,=+)}\"");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   String l = b.getImports().getByFQN("org.osgi.service.log").get("version");
   assertEquals("1.0.1", s);
   assertEquals("[1.3,1.4)", l);
 }
    public static IndexShardRoutingTable readFromThin(StreamInput in, String index)
        throws IOException {
      int iShardId = in.readVInt();
      boolean allocatedPostApi = in.readBoolean();
      Builder builder = new Builder(new ShardId(index, iShardId), allocatedPostApi);

      int size = in.readVInt();
      for (int i = 0; i < size; i++) {
        ShardRouting shard = ShardRouting.readShardRoutingEntry(in, index, iShardId);
        builder.addShard(shard);
      }

      return builder.build();
    }
예제 #7
0
  public static void testEnum() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());

    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml");
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());

    Properties p = new Properties();
    p.setProperty("r", "requireConfiguration");
    p.setProperty("i", "ignoreConfiguration");
    p.setProperty("o", "optionalConfiguration");
    Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p);
    assertEquals(Enums.X.requireConfiguration, enums.r());
    assertEquals(Enums.X.ignoreConfiguration, enums.i());
    assertEquals(Enums.X.optionalConfiguration, enums.o());
  }
예제 #8
0
  /** Test default package versions. */
  public static void testDefaultPackageVersion() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setProperty("Bundle-Version", "1.2.3");
    a.setProperty("Export-Package", "test.refer");
    Jar jar = a.build();

    Manifest m = jar.getManifest();
    Parameters exports =
        Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null);
    Map<String, String> attrs = exports.get("test.refer");
    assertNotNull(attrs);
    assertEquals("1.2.3", attrs.get("version"));
  }
예제 #9
0
 protected boolean processField(
     ObjectMapper.Builder builder, String fieldName, Object fieldNode) {
   if (fieldName.equals("date_formats") || fieldName.equals("dynamic_date_formats")) {
     List<FormatDateTimeFormatter> dateTimeFormatters = newArrayList();
     if (fieldNode instanceof List) {
       for (Object node1 : (List) fieldNode) {
         dateTimeFormatters.add(parseDateTimeFormatter(fieldName, node1));
       }
     } else if ("none".equals(fieldNode.toString())) {
       dateTimeFormatters = null;
     } else {
       dateTimeFormatters.add(parseDateTimeFormatter(fieldName, fieldNode));
     }
     if (dateTimeFormatters == null) {
       ((Builder) builder).noDynamicDateTimeFormatter();
     } else {
       ((Builder) builder).dynamicDateTimeFormatter(dateTimeFormatters);
     }
     return true;
   } else if (fieldName.equals("dynamic_templates")) {
     //  "dynamic_templates" : [
     //      {
     //          "template_1" : {
     //              "match" : "*_test",
     //              "match_mapping_type" : "string",
     //              "mapping" : { "type" : "string", "store" : "yes" }
     //          }
     //      }
     //  ]
     List tmplNodes = (List) fieldNode;
     for (Object tmplNode : tmplNodes) {
       Map<String, Object> tmpl = (Map<String, Object>) tmplNode;
       if (tmpl.size() != 1) {
         throw new MapperParsingException("A dynamic template must be defined with a name");
       }
       Map.Entry<String, Object> entry = tmpl.entrySet().iterator().next();
       ((Builder) builder)
           .add(DynamicTemplate.parse(entry.getKey(), (Map<String, Object>) entry.getValue()));
     }
     return true;
   } else if (fieldName.equals("date_detection")) {
     ((Builder) builder).dateDetection = nodeBooleanValue(fieldNode);
     return true;
   } else if (fieldName.equals("numeric_detection")) {
     ((Builder) builder).numericDetection = nodeBooleanValue(fieldNode);
     return true;
   }
   return false;
 }
예제 #10
0
 @Override
 public Settings getByPrefix(String prefix) {
   Builder builder = new Builder();
   for (Map.Entry<String, String> entry : getAsMap().entrySet()) {
     if (entry.getKey().startsWith(prefix)) {
       if (entry.getKey().length() < prefix.length()) {
         // ignore this one
         continue;
       }
       builder.put(entry.getKey().substring(prefix.length()), entry.getValue());
     }
   }
   builder.classLoader(classLoader);
   return builder.build();
 }
예제 #11
0
  public static void testADWithInheritance() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.setProperty("-metatype-inherit", "true");
    b.build();
    Resource r =
        b.getJar()
            .getResource(
                "OSGI-INF/metatype/test.metatype.MetatypeTest$TestADWithInheritanceChild.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());

    assertAD(
        d, "fromChild", "From child", "fromChild", null, null, null, 0, "String", null, null, null);
    assertAD(
        d,
        "fromSuperOne",
        "From super one",
        "fromSuperOne",
        null,
        null,
        null,
        0,
        "String",
        null,
        null,
        null);
    assertAD(
        d,
        "fromSuperTwo",
        "From super two",
        "fromSuperTwo",
        null,
        null,
        null,
        0,
        "String",
        null,
        null,
        null);
  }
예제 #12
0
  /** hardcoded imports */
  public static void testHardcodedImports() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.setProperty("-versionpolicy", "${range;[==,+)}");
    b.setProperty("Private-Package", "org.objectweb.asm");
    b.setProperty("Import-Package", "org.osgi.framework,org.objectweb.asm,abc;version=2.0.0,*");
    b.build();
    Manifest m = b.getJar().getManifest();
    m.write(System.err);
    String s = b.getImports().getByFQN("org.objectweb.asm").get("version");
    assertNull(s);
    s = b.getImports().getByFQN("abc").get("version");
    assertEquals("2.0.0", s);

    s = b.getImports().getByFQN("org.osgi.framework").get("version");
    assertEquals("[1.3,2)", s);
  }
예제 #13
0
 /**
  * See if we a can override the version from the export statement and the version from the source.
  */
 public static void testImportOverridesDiscoveredVersion() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.addClasspath(new File("bin"));
   b.setProperty("Export-Package", "org.osgi.service.event");
   b.setProperty("Private-Package", "test.refer");
   b.setProperty("Import-Package", "org.osgi.service.event;version=2.1.3.q");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("2.1.3.q", s);
 }
예제 #14
0
  private void serializeObject(final ParseContext context, String currentFieldName)
      throws IOException {
    if (currentFieldName == null) {
      throw new MapperParsingException(
          "object mapping ["
              + name
              + "] trying to serialize an object with no field associated with it, current value ["
              + context.parser().textOrNull()
              + "]");
    }
    context.path().add(currentFieldName);

    Mapper objectMapper = mappers.get(currentFieldName);
    if (objectMapper != null) {
      objectMapper.parse(context);
    } else {
      Dynamic dynamic = this.dynamic;
      if (dynamic == null) {
        dynamic = context.root().dynamic();
      }
      if (dynamic == Dynamic.STRICT) {
        throw new StrictDynamicMappingException(fullPath, currentFieldName);
      } else if (dynamic == Dynamic.TRUE) {
        // we sync here just so we won't add it twice. Its not the end of the world
        // to sync here since next operations will get it before
        synchronized (mutex) {
          objectMapper = mappers.get(currentFieldName);
          if (objectMapper == null) {
            // remove the current field name from path, since template search and the object builder
            // add it as well...
            context.path().remove();
            Mapper.Builder builder =
                context.root().findTemplateBuilder(context, currentFieldName, "object");
            if (builder == null) {
              builder = MapperBuilders.object(currentFieldName).enabled(true).pathType(pathType);
              // if this is a non root object, then explicitly set the dynamic behavior if set
              if (!(this instanceof RootObjectMapper) && this.dynamic != Defaults.DYNAMIC) {
                ((Builder) builder).dynamic(this.dynamic);
              }
            }
            BuilderContext builderContext =
                new BuilderContext(context.indexSettings(), context.path());
            objectMapper = builder.build(builderContext);
            putDynamicMapper(context, currentFieldName, objectMapper);
          } else {
            objectMapper.parse(context);
          }
        }
      } else {
        // not dynamic, read everything up to end object
        context.parser().skipChildren();
      }
    }

    context.path().remove();
  }
예제 #15
0
 /** Test if we can get the version from the source and apply the default policy. */
 public static void testVersionPolicyImportedExportsDefaultPolicy() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.addClasspath(new File("bin"));
   b.setProperty("Export-Package", "org.osgi.service.event");
   b.setProperty("Private-Package", "test.refer");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("[1.0,2)", s);
 }
예제 #16
0
  private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());

    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
  }
예제 #17
0
  /** Test import provide:. */
  public static void testExportProvided() throws Exception {
    Builder a = new Builder();
    a.addClasspath(IO.getFile("jar/osgi.jar"));
    a.addClasspath(new File("bin"));
    a.setProperty("Private-Package", "test.refer");
    a.setProperty("Export-Package", "org.osgi.service.http;provide:=true");
    Jar jar = a.build();
    Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event");
    assertEquals("[1.0,2)", event.get("version"));
    Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http");
    assertEquals("[1.2,1.3)", http.get("version"));

    Manifest m = jar.getManifest();
    String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE));
  }
예제 #18
0
  public static void updateDependencies(
      CompileContext context,
      List<File> toCompile,
      Map<ModuleBuildTarget, Collection<GroovycOutputParser.OutputItem>> successfullyCompiled,
      OutputConsumer outputConsumer,
      Builder builder)
      throws IOException {
    JavaBuilderUtil.registerFilesToCompile(context, toCompile);
    if (!successfullyCompiled.isEmpty()) {

      final Callbacks.Backend callback = JavaBuilderUtil.getDependenciesRegistrar(context);

      for (Map.Entry<ModuleBuildTarget, Collection<GroovycOutputParser.OutputItem>> entry :
          successfullyCompiled.entrySet()) {
        final ModuleBuildTarget target = entry.getKey();
        final Collection<GroovycOutputParser.OutputItem> compiled = entry.getValue();
        for (GroovycOutputParser.OutputItem item : compiled) {
          final String sourcePath = FileUtil.toSystemIndependentName(item.sourcePath);
          final String outputPath = FileUtil.toSystemIndependentName(item.outputPath);
          final File outputFile = new File(outputPath);
          final File srcFile = new File(sourcePath);
          try {
            final byte[] bytes = FileUtil.loadFileBytes(outputFile);
            if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
              LOG.info("registerCompiledClass " + outputFile + " from " + srcFile);
            }
            outputConsumer.registerCompiledClass(
                target,
                new CompiledClass(
                    outputFile, srcFile, readClassName(bytes), new BinaryContent(bytes)));
            callback.associate(outputPath, sourcePath, new FailSafeClassReader(bytes));
          } catch (Throwable e) {
            // need this to make sure that unexpected errors in, for example, ASM will not ruin the
            // compilation
            final String message =
                "Class dependency information may be incomplete! Error parsing generated class "
                    + item.outputPath;
            LOG.info(message, e);
            context.processMessage(
                new CompilerMessage(
                    builder.getPresentableName(),
                    BuildMessage.Kind.WARNING,
                    message + "\n" + CompilerMessage.getTextFromThrowable(e),
                    sourcePath));
          }
          JavaBuilderUtil.registerSuccessfullyCompiled(context, srcFile);
        }
      }
    }
  }
예제 #19
0
  public static void testSimple() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    Resource r =
        b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestSimple.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());

    assertEquals("TestSimple", xpath.evaluate("//OCD/@name", d));
    assertEquals("simple", xpath.evaluate("//OCD/@description", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//OCD/@id", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Designate/@pid", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Object/@ocdref", d));
    assertEquals("simple", xpath.evaluate("//OCD/AD[@id='simple']/@id", d));
    assertEquals("Simple", xpath.evaluate("//OCD/AD[@id='simple']/@name", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='simple']/@type", d));
    assertEquals("true", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@required", d));
    /**
     * https://github.com/bndtools/bnd/issues/281
     *
     * <p>Using the Bnd annotations library (1.52.3), the generated metatype file will have
     * required='false' for all fields annotated with @Meta.AD(). When this annotation is omitted,
     * or when the required property is explicitly set, the field is correctly marked as required.
     * Taking a glance at the code, the bug appears to be due to aQute.bnd.osgi.Annotation using
     * aQute.bnd.annotation.metatype.Configurable internally for bridging Bnd-annotations to
     * Java-annotations. This configurable only obtains the values from the Bnd-annotation, omitting
     * the defaults defined in the Java annotation. The workaround is to explicitly mention the
     * required property on each field annotated with @Meta.AD.
     */
    assertEquals("true", xpath.evaluate("//OCD/AD[@id='simple']/@required", d));
    assertEquals(
        Integer.MAX_VALUE + "", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@cardinality", d));
  }
예제 #20
0
    /**
     * Parse the mapping definition for the ontology type.
     *
     * @param name the field name
     * @param node the JSON node holding the mapping definitions.
     * @param parserContext the parser context object.
     * @return a Builder for an OntologyMapper.
     */
    @SuppressWarnings("unchecked")
    @Override
    public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
        throws MapperParsingException {
      OntologySettings ontologySettings = null;

      Builder builder = new Builder(name, threadPool);

      for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator();
          iterator.hasNext(); ) {
        Entry<String, Object> entry = iterator.next();
        if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
          ontologySettings =
              new OntologySettingsBuilder()
                  .settingsNode((Map<String, Object>) entry.getValue())
                  .build();
          iterator.remove();
        } else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
          Map<String, StringFieldMapper.Builder> builders =
              parseProperties((Map<String, Object>) entry.getValue(), parserContext);
          builder.propertyBuilders(builders);
          iterator.remove();
        }
      }

      if (ontologySettings == null) {
        throw new MapperParsingException("No ontology settings supplied");
      } else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
          && StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
        throw new MapperParsingException("No ontology URI or OLS details supplied");
      } else {
        builder = builder.ontologySettings(ontologySettings);
      }

      return builder;
    }
예제 #21
0
 @Override
 public void run() {
   builder = new Builder();
   builder.build();
   dataset = new Dataset();
   dataset.read();
   params = new Params();
   for (String group : dataset.groups()) {
     String filename = Execution.getFile("dumped-" + group + ".gz");
     out = IOUtils.openOutHard(filename);
     processExamples(group, dataset.examples(group));
     out.close();
     LogInfo.logs("Finished dumping to %s", filename);
     StopWatchSet.logStats();
   }
 }
예제 #22
0
 /** Test export annotation. */
 public static void testExportAnnotation() throws Exception {
   Builder a = new Builder();
   a.addClasspath(new File("bin"));
   a.setProperty("build", "xyz");
   a.setProperty("Export-Package", "test.versionpolicy.api");
   a.build();
   Map<String, String> attrs = a.getExports().getByFQN("test.versionpolicy.api");
   assertEquals("1.2.0.xyz", attrs.get("version"));
   assertEquals("PrivateImpl", attrs.get("exclude:"));
   assertEquals("a", attrs.get("mandatory:"));
 }
예제 #23
0
  /**
   * Tests if the implementation of the EventAdmin (which is marked as a ProviderType) causes the
   * import of the api package to use the provider version policy.
   */
  public static void testProviderType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.implemented");
    a.setExportPackage("test.versionpolicy.api");
    a.setImportPackage("test.versionpolicy.api"); // what changed so this is
    // not automatically
    // added?
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);

    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
  }
예제 #24
0
  /**
   * Tests if the implementation of the EventHandler (which is marked as a ConsumerType) causes the
   * import of the api package to use the consumer version policy.
   */
  public static void testConsumerType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.uses");
    a.setExportPackage("test.versionpolicy.api");
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);

    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,2)", attrs.get("version"));
  }
예제 #25
0
 public static IndexMetaData readFrom(StreamInput in) throws IOException {
   Builder builder = new Builder(in.readUTF());
   builder.version(in.readLong());
   builder.state(State.fromId(in.readByte()));
   builder.settings(readSettingsFromStream(in));
   int mappingsSize = in.readVInt();
   for (int i = 0; i < mappingsSize; i++) {
     MappingMetaData mappingMd = MappingMetaData.readFrom(in);
     builder.putMapping(mappingMd);
   }
   int aliasesSize = in.readVInt();
   for (int i = 0; i < aliasesSize; i++) {
     AliasMetaData aliasMd = AliasMetaData.Builder.readFrom(in);
     builder.putAlias(aliasMd);
   }
   int customSize = in.readVInt();
   for (int i = 0; i < customSize; i++) {
     String type = in.readUTF();
     Custom customIndexMetaData = lookupFactorySafe(type).readFrom(in);
     builder.putCustom(type, customIndexMetaData);
   }
   return builder.build();
 }
예제 #26
0
  /**
   * Test if the implementation of "AnnotatedProviderInterface", which is annotated with OSGi
   * R6 @ProviderType, causes import of the api package to use the provider version policy
   */
  public static void testProviderTypeR6() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setPrivatePackage("test.versionpolicy.implemented.osgi");
    b.setProperty("build", "123");

    Jar jar = b.build();
    assertTrue(b.check());
    Manifest m = jar.getManifest();
    m.write(System.err);

    Domain d = Domain.domain(m);
    Parameters params = d.getImportPackage();
    Attrs attrs = params.get("test.version.annotations.osgi");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
  }
예제 #27
0
 @Nullable
 public static Map<ModuleBuildTarget, String> getCanonicalModuleOutputs(
     CompileContext context, ModuleChunk chunk, Builder builder) {
   Map<ModuleBuildTarget, String> finalOutputs = new LinkedHashMap<ModuleBuildTarget, String>();
   for (ModuleBuildTarget target : chunk.getTargets()) {
     File moduleOutputDir = target.getOutputDir();
     if (moduleOutputDir == null) {
       context.processMessage(
           new CompilerMessage(
               builder.getPresentableName(),
               BuildMessage.Kind.ERROR,
               "Output directory not specified for module " + target.getModule().getName()));
       return null;
     }
     //noinspection ResultOfMethodCallIgnored
     moduleOutputDir.mkdirs();
     String moduleOutputPath = FileUtil.toCanonicalPath(moduleOutputDir.getPath());
     assert moduleOutputPath != null;
     finalOutputs.put(
         target, moduleOutputPath.endsWith("/") ? moduleOutputPath : moduleOutputPath + "/");
   }
   return finalOutputs;
 }
예제 #28
0
  static void assertOCD(
      Builder b,
      String cname,
      String id,
      String name,
      String description,
      String designate,
      boolean factory,
      String localization)
      throws Exception {
    Resource r = b.getJar().getResource("OSGI-INF/metatype/" + cname + ".xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    Document d = db.parse(r.openInputStream());
    assertEquals(id, xpath.evaluate("//OCD/@id", d, XPathConstants.STRING));
    assertEquals(name, xpath.evaluate("//OCD/@name", d, XPathConstants.STRING));
    assertEquals(
        localization == null ? cname : localization,
        xpath.evaluate("//OCD/@localization", d, XPathConstants.STRING));
    assertEquals(
        description == null ? "" : description,
        xpath.evaluate("//OCD/@description", d, XPathConstants.STRING));

    if (designate == null) {
      assertEquals(id, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING));
      if (factory)
        assertEquals(id, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING));
    } else {
      assertEquals(designate, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING));
      if (factory)
        assertEquals(
            designate, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING));
    }

    assertEquals(id, xpath.evaluate("//Object/@ocdref", d, XPathConstants.STRING));
  }
예제 #29
0
  /**
   * We create a JAR with the test.classreferenc.ClassReference class. This class contains a
   * javax.swing.Box.class reference Prior to Java 1.5, this was done in a silly way that is handled
   * specially. After 1.5 it is a normal reference.
   *
   * @throws Exception
   */
  public void testReference() throws Exception {
    Properties properties = new Properties();
    properties.put("-classpath", "compilerversions/compilerversions.jar");
    String[] packages = {
      "sun_1_1",
      "sun_1_6",
      "eclipse_1_1",
      "sun_1_2",
      "sun_1_3",
      "sun_1_4",
      "sun_1_5",
      "sun_jsr14",
      "eclipse_1_5",
      "eclipse_1_6",
      "eclipse_1_2",
      "eclipse_1_3",
      "eclipse_1_4",
      "eclipse_jsr14"
    };
    for (int i = 0; i < packages.length; i++) {
      Builder builder = new Builder();
      properties.put("Export-Package", packages[i]);
      builder.setProperties(properties);
      Jar jar = builder.build();
      System.out.println(builder.getErrors());
      System.out.println(builder.getWarnings());
      assertEquals(0, builder.getErrors().size());
      assertEquals(0, builder.getWarnings().size());

      Manifest manifest = jar.getManifest();
      String imports = manifest.getMainAttributes().getValue("Import-Package");
      assertTrue(
          "Package " + packages[i] + "contains swing ref", imports.indexOf("javax.swing") >= 0);
      assertFalse(
          "Package " + packages[i] + "should not contain ClassRef",
          imports.indexOf("ClassRef") >= 0);
    }
  }
예제 #30
0
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   holder = Builder.build(in);
 }