From fe08bd229687fee270acd1638a08572ddf70bc0b Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 29 Apr 2021 14:32:00 +0300 Subject: Remove buildhelpers module and dependencies to it (#12280) --- buildhelpers/pom.xml | 95 --------- .../java/com/vaadin/buildhelpers/CompileTheme.java | 159 --------------- .../buildhelpers/GeneratePackageExports.java | 224 --------------------- .../com/vaadin/buildhelpers/ManifestWriter.java | 159 --------------- client-compiled/pom.xml | 35 ---- pom.xml | 1 - themes/pom.xml | 28 --- widgets/pom.xml | 38 ---- 8 files changed, 739 deletions(-) delete mode 100644 buildhelpers/pom.xml delete mode 100644 buildhelpers/src/main/java/com/vaadin/buildhelpers/CompileTheme.java delete mode 100644 buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java delete mode 100644 buildhelpers/src/main/java/com/vaadin/buildhelpers/ManifestWriter.java diff --git a/buildhelpers/pom.xml b/buildhelpers/pom.xml deleted file mode 100644 index 69dc51c60f..0000000000 --- a/buildhelpers/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - 4.0.0 - - com.vaadin - vaadin-root - 7.7-SNAPSHOT - - com.vaadin - vaadin-buildhelpers - vaadin-buildhelpers - jar - - https://vaadin.com/ - Vaadin build helpers - - - - commons-io - commons-io - ${commons-io.version} - - - commons-cli - commons-cli - 1.2 - - - com.vaadin - vaadin-sass-compiler - ${vaadin.sass.version} - - - - com.carrotsearch - smartsprites - 0.2.10 - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - - checkstyle - - process-sources - - - - - org.apache.maven.plugins - maven-jar-plugin - - - false - - true - - - - - - maven-deploy-plugin - - true - - - - - - - - - maven-source-plugin - - true - - - - org.sonatype.plugins - nexus-staging-maven-plugin - - true - - - - - - diff --git a/buildhelpers/src/main/java/com/vaadin/buildhelpers/CompileTheme.java b/buildhelpers/src/main/java/com/vaadin/buildhelpers/CompileTheme.java deleted file mode 100644 index 06ea98ce96..0000000000 --- a/buildhelpers/src/main/java/com/vaadin/buildhelpers/CompileTheme.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2000-2021 Vaadin Ltd. - * - * Licensed under the Commercial Vaadin Developer License version 4.0 (CVDLv4); - * you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * https://vaadin.com/license/cvdl-4.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 com.vaadin.buildhelpers; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.PosixParser; - -import com.vaadin.sass.internal.ScssStylesheet; - -/** - * Helper to combine css divided into separate per component dirs into one to - * optimize http requests. - */ -public class CompileTheme { - - /** - * @param args - * @throws IOException - * @throws ParseException - */ - public static void main(String[] args) throws IOException, ParseException { - Options options = new Options(); - options.addOption("t", "theme", true, "the theme to compile"); - options.addOption("f", "theme-folder", true, - "the folder containing the theme"); - options.addOption("v", "version", true, - "the Vaadin version to compile for"); - CommandLineParser parser = new PosixParser(); - CommandLine params = parser.parse(options, args); - if (!params.hasOption("theme") || !params.hasOption("theme-folder") - || !params.hasOption("version")) { - // automatically generate the help statement - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp(CompileTheme.class.getName(), options); - return; - } - String themeName = params.getOptionValue("theme"); - String themeFolder = params.getOptionValue("theme-folder"); - String version = params.getOptionValue("version"); - - // Regular theme - try { - processSassTheme(themeFolder, themeName, "styles", version); - System.out.println( - "Compiling theme " + themeName + " styles successful"); - } catch (Exception e) { - System.err - .println("Compiling theme " + themeName + " styles failed"); - e.printStackTrace(); - } - // Legacy theme w/o .themename{} wrapping - try { - String legacyFile = themeFolder + File.separator + themeName - + File.separator + "legacy-styles.scss"; - if (new File(legacyFile).exists()) { - processSassTheme(themeFolder, themeName, "legacy-styles", - version); - System.out.println("Compiling theme " + themeName - + " legacy-styles successful"); - } - } catch (Exception e) { - System.err.println( - "Compiling theme " + themeName + " legacy-styles failed"); - e.printStackTrace(); - } - } - - private static void processSassTheme(String themeFolder, String themeName, - String variant, String version) throws Exception { - - StringBuffer cssHeader = new StringBuffer(); - - String stylesCssDir = themeFolder + File.separator + themeName - + File.separator; - - String stylesCssName = stylesCssDir + variant + ".css"; - - // Process as SASS file - String sassFile = stylesCssDir + variant + ".scss"; - - ScssStylesheet scss = ScssStylesheet.get(sassFile); - if (scss == null) { - throw new IllegalArgumentException( - "SASS file: " + sassFile + " not found"); - } - scss.compile(); - String filteredScss = scss.printState().replace("@version@", version); - - BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName)); - out.write(cssHeader.toString()); - out.write(filteredScss); - out.close(); - - System.out.println("Compiled CSS to " + stylesCssName + " (" - + filteredScss.length() + " bytes)"); - - createSprites(themeFolder, themeName); - File oldCss = new File(stylesCssName); - File newCss = new File(stylesCssDir + variant + "-sprite.css"); - - if (newCss.exists()) { - // Theme contained sprites. Renamed "styles-sprite.css" -> - // "styles.css" - oldCss.delete(); - - boolean ok = newCss.renameTo(oldCss); - if (!ok) { - throw new RuntimeException( - "Rename " + newCss + " -> " + oldCss + " failed"); - } - } - - } - - private static void createSprites(String themeFolder, String themeName) - throws FileNotFoundException, IOException { - try { - // Try loading the class separately from using it to avoid - // hiding other classpath issues - Class smartSpritesClass = org.carrot2.labs.smartsprites.SmartSprites.class; - } catch (NoClassDefFoundError e) { - System.err.println( - "Could not find smartsprites. No sprites were generated. The theme should still work."); - return; - } - - String[] parameters = new String[] { "--sprite-png-depth", "AUTO", - "--css-file-suffix", "-sprite", "--css-file-encoding", "UTF-8", - "--root-dir-path", themeFolder + File.separator + themeName, - "--log-level", "WARN" }; - - org.carrot2.labs.smartsprites.SmartSprites.main(parameters); - System.out.println("Generated sprites"); - - } -} diff --git a/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java b/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java deleted file mode 100644 index 2e2b83fce2..0000000000 --- a/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2000-2021 Vaadin Ltd. - * - * Licensed under the Commercial Vaadin Developer License version 4.0 (CVDLv4); - * you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * https://vaadin.com/license/cvdl-4.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 com.vaadin.buildhelpers; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.jar.Attributes; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import java.util.logging.Logger; -import java.util.regex.Pattern; - -/** - * Generates Export-Packages attribute for OSGi compatible manifest. - *

- * Reads the included Java packages in a jar file, generates a corresponding - * Export-Package attribute, and appends it to the jar's MANIFEST.MF. - *

- * See #3521 for details. - * - * @author magi - */ -public class GeneratePackageExports { - - private static final String EXPORT_PACKAGE_ATTRIBUTE = "Export-Package"; - - public static void main(String[] args) { - if (args.length < 2) { - System.err.println("Invalid number of parameters\n" - + "Usage: java -cp .. GenerateManifest \n" - + "Use -Dvaadin.version to specify the version to be used for the packages\n" - + "Use -DincludeNumberPackages=1 to include package names which start with a number (not 100% OSGi compatible)"); - System.exit(1); - } - - // Open the JAR - String jarFilename = args[0]; - JarFile jar = null; - try { - jar = new JarFile(jarFilename); - } catch (IOException e) { - System.err.println("Unable to open JAR '" + jarFilename + "'"); - System.exit(1); - } - - // Accepted packages - List acceptedPackagePrefixes = new ArrayList(); - for (int i = 1; i < args.length; i++) { - acceptedPackagePrefixes.add(args[i]); - } - - boolean includeNumberPackages = false; - if ("1".equals(System.getProperty("includeNumberPackages"))) { - includeNumberPackages = true; - } - - // List the included Java packages - HashSet packages = getPackages(jar, acceptedPackagePrefixes, - includeNumberPackages); - - // Avoid writing empty Export-Package attribute - if (packages.isEmpty()) { - return; - } - - String exportPackage = sortAndJoinPackages(packages); - - // Read old manifest - Manifest oldMF = null; - try { - oldMF = jar.getManifest(); - } catch (IOException e) { - e.printStackTrace(); - } - Attributes mainAttributes = oldMF.getMainAttributes(); - - String existingExportPackage = mainAttributes - .getValue(EXPORT_PACKAGE_ATTRIBUTE); - if (existingExportPackage != null) { - exportPackage = existingExportPackage + "," + exportPackage; - } - - // Jar must be closed before updating it below, as it's - // locked in Windows until closed. (#6045) - try { - jar.close(); - } catch (IOException e) { - System.err.println("Unable to close JAR '" + jarFilename + "'"); - } - - // Create the modified manifest - ManifestWriter manifest = new ManifestWriter(); - manifest.writeAttribute(EXPORT_PACKAGE_ATTRIBUTE, exportPackage); - - // Update the manifest in the Jar. The jar must be closed - // before this is done. - int status = manifest.updateJar(jarFilename); - - if (status != 0) { - System.exit(status); - } - } - - private static String sortAndJoinPackages(HashSet packages) { - // Produce an ordered listing of the package names - String packageArray[] = new String[packages.size()]; - packages.toArray(packageArray); - Arrays.sort(packageArray); - StringBuilder joinedPackages = new StringBuilder(); - for (int i = 0; i < packageArray.length; i++) { - if (i != 0) { - joinedPackages.append(","); - } - String version = getVersion(packageArray[i]); - String packageAndVersion = packageArray[i]; - if (version != null) { - packageAndVersion += ";version=\"" + version + "\""; - } else { - Logger.getLogger(GeneratePackageExports.class.getName()) - .severe("No version defined for " + packageArray[i]); - } - joinedPackages.append(packageAndVersion); - } - - return joinedPackages.toString(); - } - - /** - * Tries to find version specified using system properties of type - * version.. Searches for the packge and then its parents - * recursively. Falls back to the "vaadin.version" system property if no - * other properties are found. - * - * @param javaPackage - * The package to determine a version for - * @return A version or null if no version has been defined - */ - private static String getVersion(String javaPackage) { - String packageVersion = System.getProperty("version." + javaPackage); - if (packageVersion != null) { - return packageVersion; - } - String parentPackage = null; - if (javaPackage.contains(".")) { - parentPackage = javaPackage.substring(0, - javaPackage.lastIndexOf('.')); - String parentVersion = getVersion(parentPackage); - if (parentVersion != null) { - return parentVersion; - } - } - - String vaadinVersion = System.getProperty("vaadin.version"); - if (vaadinVersion != null) { - return vaadinVersion; - } - - return null; - } - - private static HashSet getPackages(JarFile jar, - List acceptedPackagePrefixes, - boolean includeNumberPackages) { - HashSet packages = new HashSet(); - - Pattern startsWithNumber = Pattern.compile("\\.\\d"); - - for (Enumeration it = jar.entries(); it.hasMoreElements();) { - JarEntry entry = it.nextElement(); - - boolean classFile = entry.getName().endsWith(".class"); - boolean directory = entry.isDirectory(); - - if (!classFile && !directory) { - continue; - } - - if (!acceptEntry(entry.getName(), acceptedPackagePrefixes)) { - continue; - } - - int lastSlash = entry.getName().lastIndexOf('/'); - String pkg = entry.getName().substring(0, lastSlash).replace('/', - '.'); - - if (!includeNumberPackages - && startsWithNumber.matcher(pkg).find()) { - continue; - } - - packages.add(pkg); - } - - return packages; - } - - private static boolean acceptEntry(String name, - List acceptedPackagePrefixes) { - for (String prefix : acceptedPackagePrefixes) { - if (name.startsWith(prefix)) { - return true; - } - } - return false; - } -} diff --git a/buildhelpers/src/main/java/com/vaadin/buildhelpers/ManifestWriter.java b/buildhelpers/src/main/java/com/vaadin/buildhelpers/ManifestWriter.java deleted file mode 100644 index 6696558153..0000000000 --- a/buildhelpers/src/main/java/com/vaadin/buildhelpers/ManifestWriter.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2000-2021 Vaadin Ltd. - * - * Licensed under the Commercial Vaadin Developer License version 4.0 (CVDLv4); - * you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * https://vaadin.com/license/cvdl-4.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 com.vaadin.buildhelpers; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Date; -import java.util.jar.Manifest; - -public class ManifestWriter { - StringBuffer buffer = new StringBuffer(); - - public ManifestWriter() { - } - - /** - * Writes a manifest attribute to a temporary buffer. - * - * @param name - * Attribute name - * @param value - * Attribute value - */ - public void writeAttribute(String name, String value) { - int linelen = name.length() + 2; - buffer.append(name); - buffer.append(": "); - - String remainingValue = value; - while (linelen + remainingValue.length() > 72) { - int fitsLine = 72 - linelen; - buffer.append(remainingValue.substring(0, fitsLine) + "\n "); - remainingValue = remainingValue.substring(fitsLine); - linelen = 1; - } - buffer.append(remainingValue + "\n"); - } - - /** - * Writes the manifest to given JAR file. - * - * The manifest must be created with {@code #writeAttribute(String, String)} - * before calling this write. - * - * @param jarFilename - * File name of the JAR in which the manifest is written - * @return 0 on success, nonzero value on error - */ - int updateJar(String jarFilename) { - int status = 0; - - // Determine a temporary file name - String newMfPrefix = "vaadin-manifest-" + (new Date()).getTime(); - File newMfFile = null; - try { - newMfFile = File.createTempFile(newMfPrefix, ".mf"); - } catch (IOException e) { - System.err.println("Creating temp file failed"); - status = 1; - } - - // Write the manifest to the temporary file - if (status == 0) { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(newMfFile); - fos.write(getBytes()); - fos.close(); - } catch (IOException e) { - System.err.println( - "Writing to file '" + newMfFile.getAbsolutePath() - + "' failed because: " + e.getMessage()); - status = 1; - } - } - - // Check that the manifest is OK - if (status == 0) { - Manifest checkMf = new Manifest(); - FileInputStream is; - try { - is = new FileInputStream(newMfFile); - checkMf.read(is); - } catch (IOException e) { - System.err.println( - "Reading from file '" + newMfFile.getAbsolutePath() - + "' failed because: " + e.getMessage()); - status = 1; - } - } - - // Update the manifest in the Jar - if (status == 0) { - System.out.println("Updating manifest in JAR " + jarFilename); - try { - // The "mf" order must correspond with manifest-jarfile order - Process process = Runtime.getRuntime() - .exec(new String[] { "jar", "umf", - newMfFile.getAbsolutePath(), jarFilename }); - int exitValue = process.waitFor(); - if (exitValue != 0) { - InputStream jarErr = process.getErrorStream(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(jarErr)); - while (reader.ready()) { - System.err.println("jar: " + reader.readLine()); - } - System.err.println( - "The 'jar' command returned with exit value " - + exitValue); - status = 1; - } - } catch (IOException e) { - System.err.println( - "Failed to execute 'jar' command. " + e.getMessage()); - status = 1; - } catch (InterruptedException e) { - System.err - .println("Execution of 'jar' command was interrupted. " - + e.getMessage()); - status = 1; - } - } - - // Remove the temporary file - if (newMfFile != null) { - newMfFile.delete(); - } - - return status; - } - - @Override - public String toString() { - return buffer.toString(); - } - - public byte[] getBytes() { - return buffer.toString().getBytes(); - } -} diff --git a/client-compiled/pom.xml b/client-compiled/pom.xml index 7405c4455d..b3fcd75dcf 100644 --- a/client-compiled/pom.xml +++ b/client-compiled/pom.xml @@ -43,45 +43,10 @@ provided - - ${project.groupId} - vaadin-buildhelpers - ${project.version} - provided - - - org.codehaus.mojo - exec-maven-plugin - - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=1 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/widgetsets - - - - - com.vaadin diff --git a/pom.xml b/pom.xml index d84e1b8ce5..8035295dc7 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,6 @@ - buildhelpers shared push server diff --git a/themes/pom.xml b/themes/pom.xml index 2976f4848e..58bf556e73 100644 --- a/themes/pom.xml +++ b/themes/pom.xml @@ -23,12 +23,6 @@ ${project.version} provided - - ${project.groupId} - vaadin-buildhelpers - ${project.version} - provided - com.vaadin @@ -246,29 +240,7 @@ - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=0 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/themes - - - diff --git a/widgets/pom.xml b/widgets/pom.xml index 9c4c3501e6..9c8f3c5bf4 100644 --- a/widgets/pom.xml +++ b/widgets/pom.xml @@ -44,14 +44,6 @@ provided - - ${project.groupId} - vaadin-buildhelpers - ${project.version} - provided - - - @@ -212,36 +204,6 @@ - - org.codehaus.mojo - exec-maven-plugin - - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=1 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - - com/vaadin - - - - - org.apache.maven.plugins maven-jar-plugin -- cgit v1.2.3