/* * 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.
*/
/** <samp><signature></samp> subelement for signing the NBM. */ public/*static*/ class Signature { public File keystore; public String storepass, alias; public String tsaurl, tsacert; /** Path to the keystore (private key). */ publicvoid setKeystore(File f) {
keystore = f;
} /** Password for the keystore. * If a question mark (<samp>?</samp>), the NBM will not be signed * and a warning will be printed.
*/ publicvoid setStorepass(String s) {
storepass = s;
} /** Alias for the private key. */ publicvoid setAlias(String s) {
alias = s;
} /** Time Stamping Authority (TSA) URL */ publicvoid setTsaurl(String s) {
tsaurl = s;
} /** Alias for the TSA's public key certificate */ publicvoid setTsacert(String s) {
tsacert = s;
}
}
/** List of executable files in NBM concatinated by ${line.separator}. */ public FileSet createExecutables() { return (executablesSet = new FileSet());
}
public ZipFileSet createExtraNBMFiles() { return (extraNBMFiles = new ZipFileSet());
}
/** Module manifest needed for versioning. * @deprecated Use {@link #setModule} instead.
*/
@Deprecated publicvoid setManifest(File manifest) { this.manifest = manifest; long lmod = manifest.lastModified(); if (lmod > mostRecentInput) mostRecentInput = lmod;
log(getLocation() + "The 'manifest' attr on is deprecated, please use 'module' instead", Project.MSG_WARN);
} /** Module JAR needed for generating the info file. * Information may be gotten either from its manifest, * or if it declares OpenIDE-Module-Localizing-Bundle in its * manifest, from that bundle. * The base locale variant, if any, is also checked if necessary * for the named bundle. * Currently no other locale variants of the module are examined; * the information is available but there is no published specification * of what the resulting variant NBMs (or variant information within * the NBM) should look like.
*/ publicvoid setModule(String module) { this.moduleName = module; // mostRecentInput updated below...
} /** URL to a home page describing the module. */ publicvoid setHomepage (String homepage) { this.homepage = homepage;
} /** Does module need IDE restart to be installed? */ publicvoid setNeedsrestart (String needsrestart) { this.needsrestart = needsrestart;
} /** Sets name of module author */ publicvoid setModuleauthor (String author) { this.moduleauthor = author;
} /** Install globally? */ publicvoid setGlobal (String isGlobal) { this.global = isGlobal;
} /** Is preferred update? */ publicvoid setPreferredupdate(String isPreferred) { this.preferredupdate = isPreferred;
} /** Sets pattern for target cluster */ publicvoid setTargetcluster (String targetCluster) { this.targetcluster = targetCluster;
} /** Maximum memory allowed to be used by jarsigner task. Default is 96 MB. */ publicvoid setJarSignerMaxMemory (String jsmm) { this.jarSignerMaxMemory = jsmm;
} /** Release date of NBM. */ publicvoid setReleasedate (String date) { this.releasedate = date;
} /** URL where this NBM file is expected to be downloadable from. */ publicvoid setDistribution (String distribution) throws BuildException { this.distribution = distribution; if (!(this.distribution.equals(""))) { // check the URL try {
URI uri = java.net.URI.create(this.distribution);
} catch (IllegalArgumentException ile) { thrownew BuildException("Distribution URL \"" + this.distribution + "\" is not a valid URI", ile, getLocation());
}
}
} public Blurb createLicense () { return (license = new Blurb ());
} public Blurb createNotification () { return (notification = new Blurb ());
} public Blurb createDescription () {
log(getLocation() + "The subelement in is deprecated except for emergency patches, please ensure your module has an OpenIDE-Module-Long-Description instead", Project.MSG_WARN); return desc = new Blurb();
} public Signature createSignature () { return (signature = new Signature ());
}
public ExternalPackage createExternalPackage(){
ExternalPackage externalPackage = new ExternalPackage (); if (externalPackages == null)
externalPackages = new ArrayList<>();
externalPackages.add( externalPackage ); return externalPackage;
}
private ZipFileSet main = null;
public ZipFileSet createMain () { return (main = new ZipFileSet());
}
/** Fileset for platform/modules/ext/updater.jar, to be used in DTD validation. */ public Path createUpdaterJar() { return updaterJar = new Path(getProject());
}
private Attributes getModuleAttributesForLocale(String locale) throws BuildException { if (locale == null) { thrownew BuildException("Unknown locale: null",getLocation());
}
log("Processing module attributes for locale '"+locale+"'", Project.MSG_VERBOSE);
Attributes attr; if ((!locale.equals("")) && (englishAttr != null)) {
attr = new Attributes(englishAttr);
attr.putValue("locale", locale);
log("Copying English module attributes to localized attributes in locale "+locale,Project.MSG_VERBOSE);
String om = attr.getValue("OpenIDE-Module");
String omn = attr.getValue("OpenIDE-Module-Name");
String omdc = attr.getValue("OpenIDE-Module-Display-Category");
String omsd = attr.getValue("OpenIDE-Module-Short-Description");
String omld = attr.getValue("OpenIDE-Module-Long-Description"); if (om != null) log("OpenIDE-Module"+(locale.equals("")?"":"_"+locale)+" is "+om,Project.MSG_DEBUG); if (omn != null) log("OpenIDE-Module-Name"+(locale.equals("")?"":"_"+locale)+" is "+omn,Project.MSG_DEBUG); if (omdc != null) log("OpenIDE-Module-Display-Category"+(locale.equals("")?"":"_"+locale)+" is "+omdc,Project.MSG_DEBUG); if (omsd != null) log("OpenIDE-Module-Short-Description"+(locale.equals("")?"":"_"+locale)+" is "+omsd,Project.MSG_DEBUG); if (omld != null) log("OpenIDE-Module-Long-Description"+(locale.equals("")?"":"_"+locale)+" is "+omld,Project.MSG_DEBUG);
} else {
attr = new Attributes();
attr.putValue("locale", locale);
}
moduleName = moduleName.replace(File.separatorChar, '/');
String jarName = moduleName;
String filename; String fname; String fext; if (!locale.equals("")) { // update file name for current locale
filename = moduleName.substring(moduleName.lastIndexOf('/')+1);
fname = filename.substring(0,filename.lastIndexOf('.'));
fext = filename.substring(filename.lastIndexOf('.'));
jarName = moduleName.substring(0,moduleName.lastIndexOf('/')) + "/locale/" + fname + "_"+ locale + fext;
}
log("Going to open jarfile "+jarName,Project.MSG_VERBOSE);
File mfile = new File(productDir, jarName ); if (!mfile.exists()) { // localizing jarfile does not exist, try to return english data if (englishAttr != null) {
Attributes xattr = new Attributes(englishAttr);
xattr.putValue("locale", locale); return xattr;
} else { thrownew BuildException("Unable to find English/localized data about module (locale is '"+locale+"')", getLocation());
}
} try { try (JarFile mjar = new JarFile(mfile)) { if (mjar.getManifest().getMainAttributes().getValue("Bundle-SymbolicName") != null) {
englishAttr = new Attributes();
englishAttr.putValue("OpenIDE-Module", JarWithModuleAttributes.extractCodeName(mjar.getManifest().getMainAttributes())); // #181025: treat bundles specially. returnnull;
} if (attr.getValue("OpenIDE-Module") == null ) {
attr = mjar.getManifest().getMainAttributes();
attr.putValue("locale", locale);
}
String bundlename = mjar.getManifest().getMainAttributes().getValue("OpenIDE-Module-Localizing-Bundle"); if ((bundlename == null) && (englishAttr != null)) {
String bname = englishAttr.getValue("OpenIDE-Module-Localizing-Bundle");
String bfname; String bfext; if (bname != null) {
bname = bname.replace(File.separatorChar, '/');
bfname = bname.substring(0,bname.lastIndexOf('.'));
bfext = bname.substring(bname.lastIndexOf('.'));
bundlename = bfname + "_" + locale + bfext;
log("Determined ("+locale+") localizing bundle name: "+bundlename,Project.MSG_VERBOSE);
}
} if (bundlename != null) {
Properties p = new Properties();
ZipEntry bundleentry = mjar.getEntry(bundlename); if (bundleentry != null) { try (InputStream is = mjar.getInputStream(bundleentry)) {
p.load(is);
} // Now pick up attributes from the bundle. for(String name: p.stringPropertyNames()) { if (! name.startsWith("OpenIDE-Module-")) continue;
attr.putValue(name, p.getProperty(name));
}
}
}
}
} catch (IOException ioe) { thrownew BuildException("exception while reading " + mfile.getName(), ioe, getLocation());
} if (locale.equals("") && (englishAttr == null)) {
log("Populating English module attributes", Project.MSG_VERBOSE);
englishAttr = new Attributes(attr);
}
String om = attr.getValue("OpenIDE-Module");
String omn = attr.getValue("OpenIDE-Module-Name");
String omdc = attr.getValue("OpenIDE-Module-Display-Category");
String omsd = attr.getValue("OpenIDE-Module-Short-Description");
String omld = attr.getValue("OpenIDE-Module-Long-Description"); if (om != null) log("OpenIDE-Module"+(locale.equals("")?"":"_"+locale)+" is "+om,Project.MSG_VERBOSE); if (omn != null) log("OpenIDE-Module-Name"+(locale.equals("")?"":"_"+locale)+" is "+omn,Project.MSG_VERBOSE); if (omdc != null) log("OpenIDE-Module-Display-Category"+(locale.equals("")?"":"_"+locale)+" is "+omdc,Project.MSG_VERBOSE); if (omsd != null) log("OpenIDE-Module-Short-Description"+(locale.equals("")?"":"_"+locale)+" is "+omsd,Project.MSG_VERBOSE); if (omld != null) log("OpenIDE-Module-Long-Description"+(locale.equals("")?"":"_"+locale)+" is "+omld,Project.MSG_VERBOSE); return attr;
}
@Override publicvoid execute () throws BuildException { if (productDir == null) { thrownew BuildException("must set directory of compiled product", getLocation());
} if (file == null) { thrownew BuildException("must set file for makenbm", getLocation());
} if (manifest == null && moduleName == null) { thrownew BuildException("must set module for makenbm", getLocation());
} if (manifest != null && moduleName != null) { thrownew BuildException("cannot set both manifest and module for makenbm", getLocation());
} if (locales == null) {
locales = new ArrayList<>();
}
// If desired, override the license and/or URL. //
overrideURLIfNeeded() ;
overrideLicenseIfNeeded() ;
Map<String, Supplier<Document>> moduleAttributes = new LinkedHashMap<>();
File module = new File( productDir, moduleName );
Attributes attr = getModuleAttributesForLocale(""); if (attr == null) { if (!alwaysCreateNBM) { // #181025: OSGi bundle, copy unmodified.
Copy copy = new Copy();
copy.setProject(getProject());
copy.setOwningTarget(getOwningTarget());
copy.setFile(module);
copy.setTofile(new File(nbm.getAbsolutePath().replaceFirst("[.]nbm$", ".jar")));
copy.execute(); // XXX possibly sign it // XXX could try to run pack200, though not if it was signed return;
} else {
moduleAttributes.put("", () -> createFakeOSGiInfo(module));
}
} else {
moduleAttributes.put("", () -> createInfoXml(attr));
} for (String locale : locales) {
Attributes a = getModuleAttributesForLocale(locale); if (a != null) moduleAttributes.put(locale, () -> createInfoXml(a));
}
// Will create a file Info/info.xml to be stored in tmp // The normal case; read attributes from its manifest and maybe bundle. long mMod = module.lastModified(); if (mostRecentInput < mMod) mostRecentInput = mMod;
if (mostRecentInput < nbm.lastModified()) {
log("Skipping NBM creation as most recent input is younger: " + mostRecentInput + " than the target file: " + nbm.lastModified(), Project.MSG_VERBOSE); return;
} else {
log("Most recent input: " + mostRecentInput + " file: " + nbm.lastModified(), Project.MSG_DEBUG);
}
ArrayList<ZipFileSet> infoXMLFileSets = new ArrayList<>(); for (Map.Entry<String, Supplier<Document>> modAttr : moduleAttributes.entrySet()) {
Document infoXmlContents = modAttr.getValue().get();
File infofile;
String loc = modAttr.getKey(); if (loc == null) thrownew BuildException("Found attributes without assigned locale code", getLocation()); try {
infofile = File.createTempFile("info_"+loc,".xml"); try (OutputStream infoStream = new FileOutputStream (infofile)) {
XMLUtil.write(infoXmlContents, infoStream);
}
} catch (IOException e) { thrownew BuildException("exception when creating Info/info.xml for locale '"+loc+"'", e, getLocation());
}
infofile.deleteOnExit();
ZipFileSet infoXML = new ZipFileSet();
infoXML.setFile( infofile ); if (loc.equals("")) {
infoXML.setFullpath("Info/info.xml");
} else {
infoXML.setFullpath("Info/locale/info_"+loc+".xml");
log("Adding Info/locale/info_"+loc+".xml file", Project.MSG_VERBOSE);
}
infoXMLFileSets.add(infoXML);
}
String codename = englishAttr.getValue("OpenIDE-Module"); if (codename == null) new BuildException( "Can't get codenamebase" );
UpdateTracking tracking = new UpdateTracking(productDir.getAbsolutePath());
Set<String> _files = new LinkedHashSet<>(Arrays.asList(tracking.getListOfNBM(codename)));
List<String> __files = new ArrayList<>(_files); for (String f : _files) { if (f.endsWith(".external")) { // #195041
__files.remove(f.substring(0, f.length() - 9));
}
}
String[] files = __files.toArray(new String[__files.size()]);
ZipFileSet fs = new ZipFileSet();
List <String> moduleFiles = new ArrayList <>();
fs.setDir( productDir );
String [] filesForPackaging = null; if(usePack200 && pack200excludes!=null && !pack200excludes.equals("")) {
FileSet pack200Files = new FileSet();
pack200Files.setDir(productDir);
pack200Files.setExcludes(pack200excludes);
pack200Files.setProject(getProject()); for (int i=0; i < files.length; i++) {
pack200Files.createInclude().setName( files[i] );
}
DirectoryScanner ds = pack200Files.getDirectoryScanner();
ds.scan();
filesForPackaging = ds.getIncludedFiles();
}
List<File> packedFiles = new ArrayList<>(); for (int i = 0; i < files.length; i++) { if (usePack200) {
File sourceFile = new File(productDir, files[i]); if (sourceFile.isFile() && sourceFile.getName().endsWith(".jar")) {
boolean doPackage = true; if (filesForPackaging != null) {
doPackage = false; for (String f : filesForPackaging) { if (new File(productDir, f).equals(sourceFile)) {
doPackage = true; break;
}
}
} if(doPackage) { //if both <filename>.jar and <filename>.jad exist - skip it //if both <filename>.jar and <filename>.jar.pack.gz exist - skip it for (String f : files) { if(f.equals(files[i].substring(0, files[i].lastIndexOf(".jar")) + ".jad") ||
f.equals(files[i] + ".pack.gz")) {
doPackage = false; break;
}
}
// JAR it all up together. long jarModified = nbm.lastModified(); // may be 0 //log ("Ensuring existence of NBM file " + file);
Jar jar = (Jar) getProject().createTask("jar");
jar.setDestFile(nbm);
jar.addZipfileset(fs); for (ZipFileSet zfs : infoXMLFileSets) {
jar.addFileset(zfs);
}
if (extraNBMFiles != null) {
jar.addZipfileset(extraNBMFiles);
}
if (main != null) { // Add the main dir
main.setPrefix("main"); // use main prefix
jar.addZipfileset(main);
DirectoryScanner ds = main.getDirectoryScanner();
ds.scan();
String [] mainFiles = ds.getIncludedFiles(); for(String m : mainFiles) {
moduleFiles.add(m);
}
}
privatevoid maybeAddLicenseName(Element module) { // Here we only write a name for the license. if (license != null) {
String name = license.getName(); if (name == null) { thrownew BuildException("Every license must have a name or file attribute", getLocation());
}
module.setAttribute("license", name);
}
}
privatevoid maybeAddLicense(Element module) { // Maybe write out license text. if (license != null) {
Document doc = module.getOwnerDocument();
Element el = doc.createElement("license");
el.setAttribute("name", license.getName());
el.appendChild(license.getTextNode(doc));
module.appendChild(el);
}
}
staticvoid validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task) throws IOException, SAXException {
XMLUtil.parse(input, true, false, XMLUtil.rethrowHandler(), new EntityResolver() {
ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar); public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
String remote = "http://www.netbeans.org/dtds/"; if (systemId.startsWith(remote)) {
String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length());
URL u = loader.getResource(rsrc); if (u != null) { returnnew InputSource(u.toString());
} else {
task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN);
}
} returnnull;
}
});
}
/** This returns true if the license should be overridden. */ protectedboolean overrideLicense() { return( getLicenseOverride() != null) ;
}
/** Get the license to use if the license should be overridden, * otherwise return null.
*/ protected String getLicenseOverride() {
String s = getProject().getProperty( "makenbm.override.license") ; if( s != null) { if( s.equals( "")) {
s = null ;
}
} return( s) ;
}
/** This returns true if the homepage URL should be overridden. */ protectedboolean overrideURL() { return( getURLOverride() != null) ;
}
/** Get the homepage URL to use if it should be overridden, * otherwise return null.
*/ protected String getURLOverride() {
String s = getProject().getProperty( "makenbm.override.url") ; if( s != null) { if( s.equals( "")) {
s = null ;
}
} return( s) ;
}
/** If required, this will create a new license using the override * license file.
*/ protectedvoid overrideLicenseIfNeeded() { if( overrideLicense()) {
license = new Blurb() ;
license.setFile( getProject().resolveFile( getLicenseOverride())) ;
}
}
/** If required, this will set the homepage URL using the * override value.
*/ protectedvoid overrideURLIfNeeded() { if( overrideURL()) {
homepage = getURLOverride() ;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.