use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.
the class SystemBundle method create.
/**
* Returns a bundle representing the system class loader.
*
* @param niFiProperties a NiFiProperties instance which will be used to obtain the default NAR library path,
* which will become the working directory of the returned bundle
* @return a bundle for the system class loader
*/
public static Bundle create(final NiFiProperties niFiProperties) {
final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
final String narLibraryDirectory = niFiProperties.getProperty(NiFiProperties.NAR_LIBRARY_DIRECTORY);
if (StringUtils.isBlank(narLibraryDirectory)) {
throw new IllegalStateException("Unable to create system bundle because " + NiFiProperties.NAR_LIBRARY_DIRECTORY + " was null or empty");
}
final BundleDetails systemBundleDetails = new BundleDetails.Builder().workingDir(new File(narLibraryDirectory)).coordinate(SYSTEM_BUNDLE_COORDINATE).build();
return new Bundle(systemBundleDetails, systemClassLoader);
}
use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.
the class NarBundleUtilTest method testManifestWithVersioningAndBuildInfo.
@Test
public void testManifestWithVersioningAndBuildInfo() throws IOException {
final File narDir = new File("src/test/resources/nars/nar-with-versioning");
final BundleDetails narDetails = NarBundleUtil.fromNarDirectory(narDir);
assertEquals(narDir.getPath(), narDetails.getWorkingDirectory().getPath());
assertEquals("org.apache.nifi", narDetails.getCoordinate().getGroup());
assertEquals("nifi-hadoop-nar", narDetails.getCoordinate().getId());
assertEquals("1.2.0", narDetails.getCoordinate().getVersion());
assertEquals("org.apache.nifi.hadoop", narDetails.getDependencyCoordinate().getGroup());
assertEquals("nifi-hadoop-libraries-nar", narDetails.getDependencyCoordinate().getId());
assertEquals("1.2.1", narDetails.getDependencyCoordinate().getVersion());
assertEquals("NIFI-3380", narDetails.getBuildBranch());
assertEquals("1.8.0_74", narDetails.getBuildJdk());
assertEquals("a032175", narDetails.getBuildRevision());
assertEquals("HEAD", narDetails.getBuildTag());
assertEquals("2017-01-23T10:36:27Z", narDetails.getBuildTimestamp());
assertEquals("bbende", narDetails.getBuiltBy());
}
use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.
the class JettyServer method findWars.
private Map<File, Bundle> findWars(final Set<Bundle> bundles) {
final Map<File, Bundle> wars = new HashMap<>();
// consider each nar working directory
bundles.forEach(bundle -> {
final BundleDetails details = bundle.getBundleDetails();
final File narDependencies = new File(details.getWorkingDirectory(), "META-INF/bundled-dependencies");
if (narDependencies.isDirectory()) {
// list the wars from this nar
final File[] narDependencyDirs = narDependencies.listFiles(WAR_FILTER);
if (narDependencyDirs == null) {
throw new IllegalStateException(String.format("Unable to access working directory for NAR dependencies in: %s", narDependencies.getAbsolutePath()));
}
// add each war
for (final File war : narDependencyDirs) {
wars.put(war, bundle);
}
}
});
return wars;
}
use of org.apache.nifi.bundle.BundleDetails in project nifi-minifi by apache.
the class SystemBundle method create.
/**
* Returns a bundle representing the system class loader.
*
* @param niFiProperties a NiFiProperties instance which will be used to obtain the default NAR library path,
* which will become the working directory of the returned bundle
* @return a bundle for the system class loader
*/
public static Bundle create(final NiFiProperties niFiProperties) {
final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
final String narLibraryDirectory = niFiProperties.getProperty(NiFiProperties.NAR_LIBRARY_DIRECTORY);
if (StringUtils.isBlank(narLibraryDirectory)) {
throw new IllegalStateException("Unable to create system bundle because " + NiFiProperties.NAR_LIBRARY_DIRECTORY + " was null or empty");
}
final BundleDetails systemBundleDetails = new BundleDetails.Builder().workingDir(new File(narLibraryDirectory)).coordinate(SYSTEM_BUNDLE_COORDINATE).build();
return new Bundle(systemBundleDetails, systemClassLoader);
}
use of org.apache.nifi.bundle.BundleDetails in project nifi-minifi by apache.
the class NarBundleUtil method fromNarDirectory.
/**
* Creates a BundleDetails from the given NAR working directory.
*
* @param narDirectory the directory of an exploded NAR which contains a META-INF/MANIFEST.MF
*
* @return the BundleDetails constructed from the information in META-INF/MANIFEST.MF
*/
public static BundleDetails fromNarDirectory(final File narDirectory) throws IOException, IllegalStateException {
if (narDirectory == null) {
throw new IllegalArgumentException("NAR Directory cannot be null");
}
final File manifestFile = new File(narDirectory, "META-INF/MANIFEST.MF");
try (final FileInputStream fis = new FileInputStream(manifestFile)) {
final Manifest manifest = new Manifest(fis);
final Attributes attributes = manifest.getMainAttributes();
final BundleDetails.Builder builder = new BundleDetails.Builder();
builder.workingDir(narDirectory);
final String group = attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName());
final String id = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName());
final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName());
builder.coordinate(new BundleCoordinate(group, id, version));
final String dependencyGroup = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_GROUP.getManifestName());
final String dependencyId = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_ID.getManifestName());
final String dependencyVersion = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName());
if (!StringUtils.isBlank(dependencyId)) {
builder.dependencyCoordinate(new BundleCoordinate(dependencyGroup, dependencyId, dependencyVersion));
}
builder.buildBranch(attributes.getValue(NarManifestEntry.BUILD_BRANCH.getManifestName()));
builder.buildTag(attributes.getValue(NarManifestEntry.BUILD_TAG.getManifestName()));
builder.buildRevision(attributes.getValue(NarManifestEntry.BUILD_REVISION.getManifestName()));
builder.buildTimestamp(attributes.getValue(NarManifestEntry.BUILD_TIMESTAMP.getManifestName()));
builder.buildJdk(attributes.getValue(NarManifestEntry.BUILD_JDK.getManifestName()));
builder.builtBy(attributes.getValue(NarManifestEntry.BUILT_BY.getManifestName()));
return builder.build();
}
}
Aggregations