forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
350 additions
and
49 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.nifi.nar; | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
|
||
public class NarFile { | ||
|
||
private final File file; | ||
private final NarManifest manifest; | ||
|
||
public NarFile(final File file, final NarManifest manifest) { | ||
this.file = Objects.requireNonNull(file, "File is required"); | ||
this.manifest = Objects.requireNonNull(manifest, "Manifest is required"); | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public NarManifest getManifest() { | ||
return manifest; | ||
} | ||
} |
225 changes: 225 additions & 0 deletions
225
nifi-framework-api/src/main/java/org/apache/nifi/nar/NarManifest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.nifi.nar; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.JarInputStream; | ||
import java.util.jar.Manifest; | ||
|
||
public class NarManifest { | ||
|
||
private final String group; | ||
private final String id; | ||
private final String version; | ||
|
||
private final String dependencyGroup; | ||
private final String dependencyId; | ||
private final String dependencyVersion; | ||
|
||
private final String buildTag; | ||
private final String buildRevision; | ||
private final String buildBranch; | ||
private final String buildTimestamp; | ||
private final String buildJdk; | ||
private final String builtBy; | ||
|
||
private NarManifest(final Builder builder) { | ||
this.group = Objects.requireNonNull(builder.group); | ||
this.id = Objects.requireNonNull(builder.id); | ||
this.version = Objects.requireNonNull(builder.version); | ||
|
||
this.dependencyGroup = builder.dependencyGroup; | ||
this.dependencyId = builder.dependencyId; | ||
this.dependencyVersion = builder.dependencyVersion; | ||
|
||
this.buildTag = builder.buildTag; | ||
this.buildRevision = builder.buildRevision; | ||
this.buildBranch = builder.buildBranch; | ||
this.buildTimestamp = builder.buildTimestamp; | ||
this.buildJdk = builder.buildJdk; | ||
this.builtBy = builder.builtBy; | ||
} | ||
|
||
public String getGroup() { | ||
return group; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public String getDependencyGroup() { | ||
return dependencyGroup; | ||
} | ||
|
||
public String getDependencyId() { | ||
return dependencyId; | ||
} | ||
|
||
public String getDependencyVersion() { | ||
return dependencyVersion; | ||
} | ||
|
||
public String getBuildTag() { | ||
return buildTag; | ||
} | ||
|
||
public String getBuildRevision() { | ||
return buildRevision; | ||
} | ||
|
||
public String getBuildBranch() { | ||
return buildBranch; | ||
} | ||
|
||
public String getBuildTimestamp() { | ||
return buildTimestamp; | ||
} | ||
|
||
public String getBuildJdk() { | ||
return buildJdk; | ||
} | ||
|
||
public String getBuiltBy() { | ||
return builtBy; | ||
} | ||
|
||
public static NarManifest fromFile(final File narFile) throws IOException { | ||
try (final InputStream inputStream = new FileInputStream(narFile)) { | ||
return fromInputStream(inputStream); | ||
} | ||
} | ||
|
||
public static NarManifest fromInputStream(final InputStream inputStream) throws IOException { | ||
try (final JarInputStream jarInputStream = new JarInputStream(inputStream)) { | ||
final Manifest manifest = jarInputStream.getManifest(); | ||
if (manifest == null) { | ||
throw new IllegalStateException("NAR content is missing required META-INF/MANIFEST entry"); | ||
} | ||
|
||
final Attributes attributes = manifest.getMainAttributes(); | ||
|
||
return NarManifest.builder() | ||
.group(attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName())) | ||
.id(attributes.getValue(NarManifestEntry.NAR_ID.getManifestName())) | ||
.version(attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName())) | ||
.dependencyGroup(attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_GROUP.getManifestName())) | ||
.dependencyId(attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_ID.getManifestName())) | ||
.dependencyVersion(attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName())) | ||
.buildTag(attributes.getValue(NarManifestEntry.BUILD_TAG.getManifestName())) | ||
.buildRevision(attributes.getValue(NarManifestEntry.BUILD_REVISION.getManifestName())) | ||
.buildBranch(attributes.getValue(NarManifestEntry.BUILD_BRANCH.getManifestName())) | ||
.buildTimestamp(attributes.getValue(NarManifestEntry.BUILD_TIMESTAMP.getManifestName())) | ||
.buildJdk(attributes.getValue(NarManifestEntry.BUILD_JDK.getManifestName())) | ||
.builtBy(attributes.getValue(NarManifestEntry.BUILT_BY.getManifestName())) | ||
.build(); | ||
} | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
private String group; | ||
private String id; | ||
private String version; | ||
private String dependencyGroup; | ||
private String dependencyId; | ||
private String dependencyVersion; | ||
private String buildTag; | ||
private String buildRevision; | ||
private String buildBranch; | ||
private String buildTimestamp; | ||
private String buildJdk; | ||
private String builtBy; | ||
|
||
public Builder group(final String group) { | ||
this.group = group; | ||
return this; | ||
} | ||
|
||
public Builder id(final String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public Builder version(final String version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
public Builder dependencyGroup(final String dependencyGroup) { | ||
this.dependencyGroup = dependencyGroup; | ||
return this; | ||
} | ||
|
||
public Builder dependencyId(final String dependencyId) { | ||
this.dependencyId = dependencyId; | ||
return this; | ||
} | ||
|
||
public Builder dependencyVersion(final String dependencyVersion) { | ||
this.dependencyVersion = dependencyVersion; | ||
return this; | ||
} | ||
|
||
public Builder buildTag(final String buildTag) { | ||
this.buildTag = buildTag; | ||
return this; | ||
} | ||
|
||
public Builder buildRevision(final String buildRevision) { | ||
this.buildRevision = buildRevision; | ||
return this; | ||
} | ||
|
||
public Builder buildBranch(final String buildBranch) { | ||
this.buildBranch = buildBranch; | ||
return this; | ||
} | ||
|
||
public Builder buildTimestamp(final String buildTimestamp) { | ||
this.buildTimestamp = buildTimestamp; | ||
return this; | ||
} | ||
|
||
public Builder buildJdk(final String buildJdk) { | ||
this.buildJdk = buildJdk; | ||
return this; | ||
} | ||
|
||
public Builder builtBy(final String builtBy) { | ||
this.builtBy = builtBy; | ||
return this; | ||
} | ||
|
||
public NarManifest build() { | ||
return new NarManifest(this); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.