http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/converters/fontkit/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/converters/fontkit/pom.xml b/flex-maven-tools/mavenizer/converters/fontkit/pom.xml new file mode 100644 index 0000000..3d472e0 --- /dev/null +++ b/flex-maven-tools/mavenizer/converters/fontkit/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>converters</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>fontkit-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>base-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + </dependencies> + +</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/converters/fontkit/src/main/java/org/apache/flex/utilities/converter/fontkit/FontkitConverter.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/converters/fontkit/src/main/java/org/apache/flex/utilities/converter/fontkit/FontkitConverter.java b/flex-maven-tools/mavenizer/converters/fontkit/src/main/java/org/apache/flex/utilities/converter/fontkit/FontkitConverter.java new file mode 100644 index 0000000..81fbe09 --- /dev/null +++ b/flex-maven-tools/mavenizer/converters/fontkit/src/main/java/org/apache/flex/utilities/converter/fontkit/FontkitConverter.java @@ -0,0 +1,74 @@ +package org.apache.flex.utilities.converter.fontkit; + +import org.apache.flex.utilities.converter.BaseConverter; +import org.apache.flex.utilities.converter.Converter; +import org.apache.flex.utilities.converter.exceptions.ConverterException; +import org.apache.flex.utilities.converter.model.MavenArtifact; + +import java.io.File; + +/** + * Created by christoferdutz on 06.04.15. + */ +public class FontkitConverter extends BaseConverter implements Converter { + + public FontkitConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException { + super(rootSourceDirectory, rootTargetDirectory); + } + + @Override + protected void processDirectory() throws ConverterException { + File fontkitRootDir = new File(rootSourceDirectory, "lib/external/optional"); + if(!fontkitRootDir.exists() || !fontkitRootDir.isDirectory()) { + System.out.println("Skipping Fontkit generation."); + return; + } + + File afeJar = new File(fontkitRootDir, "afe.jar"); + File aglj40Jar = new File(fontkitRootDir, "aglj40.jar"); + File rideauJar = new File(fontkitRootDir, "rideau.jar"); + File flexFontkitJar = new File(fontkitRootDir, "flex-fontkit.jar"); + + if(!afeJar.exists() || !aglj40Jar.exists() || !rideauJar.exists() || !flexFontkitJar.exists()) { + throw new ConverterException("Fontkit directory '" + fontkitRootDir.getPath() + "' must contain the jar " + + "files afe.jar, aglj40.jar, rideau.jar and flex-fontkit.jar."); + } + + final MavenArtifact fontkit = new MavenArtifact(); + fontkit.setGroupId("com.adobe"); + fontkit.setArtifactId("fontkit"); + fontkit.setVersion("1.0"); + fontkit.setPackaging("jar"); + fontkit.addDefaultBinaryArtifact(flexFontkitJar); + + final MavenArtifact afe = new MavenArtifact(); + afe.setGroupId("com.adobe.fontkit"); + afe.setArtifactId("afe"); + afe.setVersion("1.0"); + afe.setPackaging("jar"); + afe.addDefaultBinaryArtifact(afeJar); + fontkit.addDependency(afe); + + final MavenArtifact aglj40 = new MavenArtifact(); + aglj40.setGroupId("com.adobe.fontkit"); + aglj40.setArtifactId("aglj40"); + aglj40.setVersion("1.0"); + aglj40.setPackaging("jar"); + aglj40.addDefaultBinaryArtifact(aglj40Jar); + fontkit.addDependency(aglj40); + + final MavenArtifact rideau = new MavenArtifact(); + rideau.setGroupId("com.adobe.fontkit"); + rideau.setArtifactId("rideau"); + rideau.setVersion("1.0"); + rideau.setPackaging("jar"); + rideau.addDefaultBinaryArtifact(rideauJar); + fontkit.addDependency(rideau); + + writeArtifact(afe); + writeArtifact(aglj40); + writeArtifact(rideau); + writeArtifact(fontkit); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/converters/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/converters/pom.xml b/flex-maven-tools/mavenizer/converters/pom.xml new file mode 100644 index 0000000..69a859b --- /dev/null +++ b/flex-maven-tools/mavenizer/converters/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>apache-flex-sdk-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>converters</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <!-- Module defining all the base functionality shared among the other converters --> + <module>base</module> + + <!-- The individual converter implementations --> + <module>air</module> + <module>flash</module> + <module>flex</module> + <module>fontkit</module> + <module>wrapper</module> + </modules> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/converters/wrapper/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/converters/wrapper/pom.xml b/flex-maven-tools/mavenizer/converters/wrapper/pom.xml new file mode 100644 index 0000000..86f8a43 --- /dev/null +++ b/flex-maven-tools/mavenizer/converters/wrapper/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>converters</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>wrapper-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>base-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java b/flex-maven-tools/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java new file mode 100644 index 0000000..7e4af4c --- /dev/null +++ b/flex-maven-tools/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java @@ -0,0 +1,93 @@ +package org.apache.flex.utilities.converter.wrapper; + +import org.apache.flex.utilities.converter.BaseConverter; +import org.apache.flex.utilities.converter.Converter; +import org.apache.flex.utilities.converter.exceptions.ConverterException; +import org.apache.flex.utilities.converter.model.MavenArtifact; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; + +/** + * Created by christoferdutz on 06.04.15. + */ +public class WrapperConverter extends BaseConverter implements Converter { + + public WrapperConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException { + super(rootSourceDirectory, rootTargetDirectory); + } + + @Override + protected void processDirectory() throws ConverterException { + File wrapperRootDir = new File(rootSourceDirectory, "templates/swfobject"); + if(!wrapperRootDir.exists() || !wrapperRootDir.isDirectory()) { + System.out.println("Skipping Wrapper generation."); + return; + } + + try { + // Rename the index.template.html to index.html + File indexHtml = new File(wrapperRootDir, "index.template.html"); + if(!indexHtml.renameTo(new File(wrapperRootDir, "index.html"))) { + System.out.println("Could not rename index.template.html to index.html."); + } + + final File wrapperWar = File.createTempFile("SWFObjectWrapper-2.2", ".war"); + generateZip(wrapperRootDir.listFiles(), wrapperWar); + + final MavenArtifact swfobjectWrapper = new MavenArtifact(); + swfobjectWrapper.setGroupId("org.apache.flex.wrapper"); + swfobjectWrapper.setArtifactId("swfobject"); + swfobjectWrapper.setVersion(getFlexVersion(rootSourceDirectory)); + swfobjectWrapper.setPackaging("war"); + swfobjectWrapper.addDefaultBinaryArtifact(wrapperWar); + + writeArtifact(swfobjectWrapper); + } catch (IOException e) { + throw new ConverterException("Error creating wrapper war.", e); + } + } + + /** + * Get the version of an Flex SDK from the content of the SDK directory. + * + * @return version string for the current Flex SDK + */ + protected String getFlexVersion(File rootDirectory) throws ConverterException { + final File sdkDescriptor = new File(rootDirectory, "flex-sdk-description.xml"); + + // If the descriptor is not present, return null as this FDK directory doesn't + // seem to contain a Flex SDK. + if(!sdkDescriptor.exists()) { + return null; + } + + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try { + // Parse the document + final DocumentBuilder db = dbf.newDocumentBuilder(); + final Document dom = db.parse(sdkDescriptor); + + // Get name, version and build nodes + final Element root = dom.getDocumentElement(); + final String version = root.getElementsByTagName("version").item(0).getTextContent(); + final String build = root.getElementsByTagName("build").item(0).getTextContent(); + + // In general the version consists of the content of the version element with an appended build-number. + return (build.equals("0")) ? version + "-SNAPSHOT" : version; + } catch (ParserConfigurationException pce) { + throw new RuntimeException(pce); + } catch (SAXException se) { + throw new RuntimeException(se); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/deployers/aether/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/deployers/aether/pom.xml b/flex-maven-tools/mavenizer/deployers/aether/pom.xml new file mode 100644 index 0000000..692b99c --- /dev/null +++ b/flex-maven-tools/mavenizer/deployers/aether/pom.xml @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>deployers</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>aether-deployer</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addClasspath>true</addClasspath> + <mainClass>org.apache.flex.utilities.converter.deployer.aether.AetherDeployer</mainClass> + </manifest> + <manifestEntries> + <Implementation-Build>${project.version}</Implementation-Build> + </manifestEntries> + </archive> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <finalName>aether-deployer-${project.version}-full</finalName> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-api</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-util</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-impl</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-spi</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-connector-basic</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-transport-file</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-transport-http</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-transport-wagon</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.aether</groupId> + <artifactId>aether-transport-classpath</artifactId> + <version>${aetherVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-aether-provider</artifactId> + <version>${mavenVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.wagon</groupId> + <artifactId>wagon-ssh</artifactId> + <version>${wagonVersion}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java b/flex-maven-tools/mavenizer/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java new file mode 100644 index 0000000..89b991b --- /dev/null +++ b/flex-maven-tools/mavenizer/deployers/aether/src/main/java/org/apache/flex/utilities/converter/deployer/aether/AetherDeployer.java @@ -0,0 +1,248 @@ +/* + * 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.flex.utilities.converter.deployer.aether; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; +import org.apache.maven.repository.internal.DefaultVersionRangeResolver; +import org.apache.maven.repository.internal.DefaultVersionResolver; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.deployment.DeploymentException; +import org.eclipse.aether.impl.*; +import org.eclipse.aether.installation.InstallationException; +import org.eclipse.aether.internal.impl.DefaultDependencyCollector; +import org.eclipse.aether.internal.impl.DefaultTransporterProvider; +import org.eclipse.aether.repository.Authentication; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; +import org.eclipse.aether.spi.connector.transport.TransporterFactory; +import org.eclipse.aether.spi.connector.transport.TransporterProvider; +import org.eclipse.aether.transport.file.FileTransporterFactory; +import org.eclipse.aether.transport.http.HttpTransporterFactory; +import org.eclipse.aether.transport.wagon.WagonTransporterFactory; +import org.eclipse.aether.util.repository.AuthenticationBuilder; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +/** + * Updated Version of the SDKDeployer which no longer relies on an installed Maven + * system and which performs the deployment inside the VM without having to spawn new + * VMs for each artifact in order to deploy the files using a Maven commandline + * execution. + * + * Created with IntelliJ IDEA. + * Date: 03.11.13 + */ +public class AetherDeployer { + + private File directory; + private String url; + private String username; + private String password; + + public AetherDeployer(File directory, String url, String username, String password) { + this.directory = directory; + this.url = url; + this.username = username; + this.password = password; + } + + public AetherDeployer(String[] parameters) { + this.directory = new File(parameters[0]); + this.url = parameters[1]; + if (parameters.length > 2) { + this.username = parameters[2]; + this.password = parameters[3]; + } + } + + public static void main(String[] args) { + if ((args.length != 2) && (args.length != 4)) { + printUsage(); + System.exit(0); + } + + final AetherDeployer deployer = new AetherDeployer(args); + deployer.deploy(); + } + + private static void printUsage() { + System.out.println("\nUsage: java -cp flex-sdk-converter-1.0.jar SDKInVMDeployer \"directory\" \"url\" [\"username\", \"password\"]\n"); + System.out.println("The SDKDeployer needs at least 2 ordered parameters separated by spaces:"); + System.out.println("\t1- directory: The path to the directory containing the artifacts that should be deployed."); + System.out.println("\t2- url: URL where the artifacts will be deployed."); + System.out.println("If the targeted repository requires authentication two more parameters have to be provided:"); + System.out.println("\t3- username: The username used to authenticate on the target repository."); + System.out.println("\t4- password: The password used to authenticate on the target repository."); + } + + public void deploy() { + try { + final DefaultServiceLocator locator = new DefaultServiceLocator(); + locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); + locator.addService(VersionResolver.class, DefaultVersionResolver.class); + locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class); + locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class); + locator.addService(DependencyCollector.class, DefaultDependencyCollector.class); + locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); + locator.addService(TransporterProvider.class, DefaultTransporterProvider.class); + locator.addService(TransporterFactory.class, FileTransporterFactory.class); + locator.addService(TransporterFactory.class, HttpTransporterFactory.class); + locator.addService(TransporterFactory.class, WagonTransporterFactory.class); + + final RepositorySystem repositorySystem = locator.getService(RepositorySystem.class); + + if (repositorySystem == null) { + System.out.println("Couldn't initialize local maven repository system."); + System.exit(0); + } else { + // Setup the repository system session based upon the current maven settings.xml. + final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + final LocalRepository localRepo = new LocalRepository(directory); + RemoteRepository.Builder repoBuilder = new RemoteRepository.Builder("repo", "default", url); + if ((username != null) && (password != null)) { + final Authentication authentication = new AuthenticationBuilder().addUsername( + username).addPassword(password).build(); + repoBuilder.setAuthentication(authentication); + } + final RemoteRepository remoteRepository = repoBuilder.build(); + + session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepo)); + + // Process all content of the mavenizer target directory. + final File rootDir = directory; + processDir(rootDir, repositorySystem, session, remoteRepository); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + private void processDir(File curDir, RepositorySystem repositorySystem, RepositorySystemSession session, + RemoteRepository remoteRepository) + throws IOException, XmlPullParserException, InstallationException, DeploymentException { + // If the current directory contained any poms, + // process them as artifacts. + final File[] poms = curDir.listFiles(new PomFilter()); + if (poms != null) { + for (File pom : poms) { + processArtifact(pom, repositorySystem, session, remoteRepository); + } + } + + // If the current directory contained any directories, + // continue processing their content. + final File[] dirs = curDir.listFiles(new DirFilter()); + if (dirs != null) { + for (File dir : dirs) { + processDir(dir, repositorySystem, session, remoteRepository); + } + } + } + + private void processArtifact(File pomFile, RepositorySystem repositorySystem, RepositorySystemSession session, + RemoteRepository remoteRepository) + throws IOException, XmlPullParserException, InstallationException, DeploymentException { + final Reader reader = new FileReader(pomFile); + try { + final File artifactDirectory = pomFile.getParentFile(); + final MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); + final Model model = xpp3Reader.read(reader); + + // Make the deployer deploy the pom itself. + final DeployRequest artifactInstallRequest = new DeployRequest(); + artifactInstallRequest.setRepository(remoteRepository); + Artifact pomArtifact = new DefaultArtifact( + model.getGroupId(), model.getArtifactId(), "pom", model.getVersion()); + pomArtifact = pomArtifact.setFile(pomFile); + artifactInstallRequest.addArtifact(pomArtifact); + + // Add any additional files to this installation. + final String artifactBaseName = model.getArtifactId() + "-" + model.getVersion(); + final File artifactFiles[] = artifactDirectory.listFiles(new ArtifactFilter()); + for (final File artifactFile : artifactFiles) { + final String fileName = artifactFile.getName(); + + // Handle the case that some file might not start with the base-name. + if(!fileName.startsWith(artifactBaseName)) { + continue; + } + + final String classifier; + // This file has a classifier. + if (fileName.charAt(artifactBaseName.length()) == '-') { + classifier = fileName.substring(artifactBaseName.length() + 1, + fileName.indexOf(".", artifactBaseName.length())); + } + // This file doesn't have a classifier. + else { + classifier = ""; + } + final String extension = fileName.substring( + artifactBaseName.length() + 1 + ((classifier.length() > 0) ? classifier.length() + 1 : 0)); + Artifact fileArtifact = new DefaultArtifact(model.getGroupId(), model.getArtifactId(), + classifier, extension, model.getVersion()); + fileArtifact = fileArtifact.setFile(artifactFile); + artifactInstallRequest.addArtifact(fileArtifact); + } + + // Actually install the artifact. + System.out.println("Installing Artifact: " + pomArtifact.getGroupId() + ":" + + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion()); + for (final Artifact artifact : artifactInstallRequest.getArtifacts()) { + System.out.println(" - File with extension " + artifact.getExtension() + + ((artifact.getClassifier().length() > 0) ? " and classifier " + artifact.getClassifier() : "")); + } + + repositorySystem.deploy(session, artifactInstallRequest); + } finally { + reader.close(); + } + } + + private class PomFilter implements java.io.FileFilter { + public boolean accept(File pathname) { + return pathname.getName().endsWith(".pom"); + } + } + + private class DirFilter implements java.io.FileFilter { + public boolean accept(File pathname) { + return pathname.isDirectory(); + } + } + + private class ArtifactFilter implements java.io.FileFilter { + public boolean accept(File pathname) { + return !pathname.getName().endsWith(".pom") && !pathname.isDirectory(); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/deployers/maven/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/deployers/maven/pom.xml b/flex-maven-tools/mavenizer/deployers/maven/pom.xml new file mode 100644 index 0000000..c1fc93c --- /dev/null +++ b/flex-maven-tools/mavenizer/deployers/maven/pom.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>deployers</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>maven-deployer</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addClasspath>true</addClasspath> + <mainClass>org.apache.flex.utilities.converter.deployer.maven.MavenDeployer</mainClass> + </manifest> + <manifestEntries> + <Implementation-Build>${project.version}</Implementation-Build> + </manifestEntries> + </archive> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <finalName>maven-deployer-${project.version}-full</finalName> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/deployers/maven/src/main/java/org/apache/flex/utilities/converter/deployer/maven/MavenDeployer.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/deployers/maven/src/main/java/org/apache/flex/utilities/converter/deployer/maven/MavenDeployer.java b/flex-maven-tools/mavenizer/deployers/maven/src/main/java/org/apache/flex/utilities/converter/deployer/maven/MavenDeployer.java new file mode 100644 index 0000000..6b2da53 --- /dev/null +++ b/flex-maven-tools/mavenizer/deployers/maven/src/main/java/org/apache/flex/utilities/converter/deployer/maven/MavenDeployer.java @@ -0,0 +1,185 @@ +/* + * 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.flex.utilities.converter.deployer.maven; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * Date: 11.08.12 + * Time: 18:17 + */ +public class MavenDeployer { + + private String directory; + private String repositoryId; + private String url; + private String mvn; + + /** + * @param parameters + */ + public MavenDeployer(String[] parameters) { + super(); + this.directory = parameters[0]; + this.repositoryId = parameters[1]; + this.url = parameters[2]; + this.mvn = parameters[3]; + } + + public static void main(String[] args) { + if (args.length != 4) { + printUsage(); + System.exit(0); + } + + MavenDeployer deployer = new MavenDeployer(args); + deployer.start(); + } + + private static void printUsage() { + System.out.println("\nUsage: java -cp flex-sdk-converter-1.0.jar org.apache.flex.utilities.converter.deployer.maven.SDKDeployer \"directory\" \"repositoryId\" \"url\" \"mvn\"\n"); + System.out.println("The org.apache.flex.utilities.converter.deployer.maven.SDKDeployer needs 4 ordered parameters separated by spaces:"); + System.out.println("\t1- directory: The path to the directory to deploy."); + System.out.println("\t2- repositoryId: Server Id to map on the <id> under <server> section of settings.xml."); + System.out.println("\t3- url: URL where the artifacts will be deployed."); + System.out.println("\t4- mvn: The path to the mvn.bat / mvn.sh."); + } + + private void start() { + try { + File dir = new File(directory); + + doDir(dir); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + private void doDir(File dir) throws IOException, InterruptedException { + File[] listFiles = dir.listFiles(new PomFilter()); + if (listFiles != null) { + for (File pom : listFiles) { + doPom(pom); + } + } + + File[] listDirs = dir.listFiles(new DirFilter()); + if (listDirs != null) { + for (File subdir : listDirs) { + doDir(subdir); + } + } + } + + private void doPom(File pom) throws IOException, InterruptedException { + File base = pom.getParentFile(); + final String fileName = pom.getName(); + String artifactName = fileName.substring(0, fileName.lastIndexOf("-")); + + if (artifactName != null) { + File artifacts[] = new File(pom.getParent()).listFiles(new ArtifactFilter()); + List<String> processCmdBase = new ArrayList<String>(10); + processCmdBase.add(mvn); + processCmdBase.add("deploy:deploy-file"); + processCmdBase.add("-DrepositoryId=" + repositoryId); + processCmdBase.add("-Durl=" + url); + + ProcessBuilder processBuilder = null; + + + String packaging; + String classifier = null; + + List<String> processCmd = null; + if (artifacts != null && artifacts.length > 0) { + for (File artifact : artifacts) { + processCmd = new ArrayList<String>(10); + processCmd.addAll(processCmdBase); + classifier = packaging = null; + artifactName = artifact.getName(); + + packaging = (artifactName.endsWith("rb.swc")) ? "rb.swc" : artifactName.substring(artifactName.lastIndexOf(".") + 1); + + try { + classifier = artifactName + .substring(artifactName.indexOf(base.getName()) + base.getName().length() + 1, artifactName.length() - packaging.length() - 1); + } catch (StringIndexOutOfBoundsException ex) {/*has no classifier*/} + + processCmd.add("-Dfile=" + artifact.getAbsolutePath()); + processCmd.add("-DpomFile=" + pom.getAbsolutePath()); + if (classifier != null && classifier.length() > 0) { + processCmd.add("-Dclassifier=" + classifier); + } + processCmd.add("-Dpackaging=" + packaging); + processBuilder = new ProcessBuilder(processCmd); + exec(processBuilder.start()); + } + } else { + processCmd = new ArrayList<String>(10); + processCmd.addAll(processCmdBase); + processCmd.add("-Dfile=" + pom.getAbsolutePath()); + processCmd.add("-DpomFile=" + pom.getAbsolutePath()); + processBuilder = new ProcessBuilder(processCmd); + exec(processBuilder.start()); + } + + } + } + + private void exec(Process p) throws InterruptedException, IOException { + String line; + BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = bri.readLine()) != null) { + System.out.println(line); + } + while ((line = bre.readLine()) != null) { + System.out.println(line); + } + p.waitFor(); + bri.close(); + bre.close(); + System.out.println("Done."); + } + + private class PomFilter implements java.io.FileFilter { + + @Override + public boolean accept(File pathname) { + return pathname.getName().endsWith(".pom"); + } + } + + private class DirFilter implements java.io.FileFilter { + + @Override + public boolean accept(File pathname) { + return pathname.isDirectory(); + } + } + + private class ArtifactFilter implements java.io.FileFilter { + + @Override + public boolean accept(File pathname) { + return !pathname.getName().endsWith(".pom"); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/deployers/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/deployers/pom.xml b/flex-maven-tools/mavenizer/deployers/pom.xml new file mode 100644 index 0000000..692b45d --- /dev/null +++ b/flex-maven-tools/mavenizer/deployers/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>apache-flex-sdk-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>deployers</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>maven</module> + <module>aether</module> + </modules> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/maven-extension/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/maven-extension/pom.xml b/flex-maven-tools/mavenizer/maven-extension/pom.xml new file mode 100644 index 0000000..4a96355 --- /dev/null +++ b/flex-maven-tools/mavenizer/maven-extension/pom.xml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>apache-flex-sdk-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>maven-extension</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <build> + <plugins> + <plugin> + <groupId>org.sonatype.plugins</groupId> + <artifactId>sisu-maven-plugin</artifactId> + <version>1.4</version> + <executions> + <execution> + <id>generate-index</id> + <goals> + <goal>main-index</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.4</version> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <finalName>flex-maven-extension-${project.version}</finalName> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>download-retriever</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>flex-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>flash-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>air-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>fontkit-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>wrapper-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>3.1.1</version> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java b/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java new file mode 100644 index 0000000..034636d --- /dev/null +++ b/flex-maven-tools/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java @@ -0,0 +1,241 @@ +package org.apache.flex.utilities.converter.mavenextension; + +import org.apache.commons.io.FileUtils; +import org.apache.flex.utilities.converter.air.AirConverter; +import org.apache.flex.utilities.converter.flash.FlashConverter; +import org.apache.flex.utilities.converter.flex.FlexConverter; +import org.apache.flex.utilities.converter.fontkit.FontkitConverter; +import org.apache.flex.utilities.converter.retrievers.download.DownloadRetriever; +import org.apache.flex.utilities.converter.retrievers.types.PlatformType; +import org.apache.flex.utilities.converter.retrievers.types.SdkType; +import org.apache.flex.utilities.converter.wrapper.WrapperConverter; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.eventspy.AbstractEventSpy; +import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.logging.Logger; +import org.eclipse.aether.RepositoryEvent; +import org.eclipse.aether.artifact.Artifact; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import java.io.File; + +/** + * Maven EventSpy that listens for resolution requests and in case of Flex related + * artifacts, it pre-checks their availability. If they are not available, it uses + * the apache flex sdk converter to automatically download and convert the missing + * artifacts before continuing the build normally. + * + * Created by christoferdutz on 17.04.15. + */ +@Named +@Singleton +public class FlexEventSpy extends AbstractEventSpy { + + @Inject + protected RepositorySystem repositorySystem; + + @Inject + protected Logger logger; + + protected MavenSession mavenSession; + + protected boolean internalLookup = false; + protected boolean flexSplashScreenShown = false; + + public FlexEventSpy() { + } + + @Override + public void init(Context context) throws Exception { + } + + @Override + public void onEvent(Object o) throws Exception { + if(o instanceof ExecutionEvent) { + mavenSession = ((ExecutionEvent) o).getSession(); + } else if(o instanceof RepositoryEvent) { + RepositoryEvent repositoryEvent = (RepositoryEvent) o; + if(repositoryEvent.getType() == RepositoryEvent.EventType.ARTIFACT_RESOLVING) { + if(!internalLookup) { + try { + internalLookup = true; + Artifact artifact = repositoryEvent.getArtifact(); + + if (artifact.getGroupId().startsWith("org.apache.flex") && + !"rb.swc".equals(artifact.getExtension())) { + // Output a cool spash-screen ... sorry for that ... couldn't resist :-) + if(!flexSplashScreenShown) { + showFlexSplashScreen(); + } + + if(!canResolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getExtension(), artifact.getClassifier())) { + initFlex(artifact.getVersion()); + } + } else if (artifact.getGroupId().startsWith("com.adobe.flash")) { + if(!canResolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getExtension(), artifact.getClassifier())) { + initFlash(artifact.getVersion()); + } + } else if (artifact.getGroupId().startsWith("com.adobe.air")) { + if(!canResolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getExtension(), artifact.getClassifier())) { + initAir(artifact.getVersion()); + } + } else if (artifact.getGroupId().equals("com.adobe") && artifact.getArtifactId().equals("fontkit")) { + if(!canResolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + artifact.getExtension(), artifact.getClassifier())) { + initFontkit(); + } + } + } finally { + internalLookup = false; + } + } + } + } + } + + protected boolean canResolve(String groupId, String artifactId, String version, + String type, String classifier) { + try { + ArtifactResolutionRequest req = new ArtifactResolutionRequest(); + req.setLocalRepository(mavenSession.getLocalRepository()); + req.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories()); + if((classifier == null) || (classifier.length() == 0)) { + req.setArtifact(repositorySystem.createArtifact(groupId, artifactId, version, type)); + } else { + req.setArtifact(repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, type, classifier)); + } + ArtifactResolutionResult res = repositorySystem.resolve(req); + return res.isSuccess(); + } catch (Throwable e) { + return false; + } + } + + protected void initFlex(String version) throws MavenExecutionException { + logger.info("==========================================================="); + logger.info(" - Installing Apache Flex SDK " + version); + try { + File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir()); + DownloadRetriever downloadRetriever = new DownloadRetriever(); + File sdkRoot = downloadRetriever.retrieve(SdkType.FLEX, version); + + // In order to create a fully functional wrapper we need to download + // SWFObject and merge that with the fdk first. + File swfObjectRoot = downloadRetriever.retrieve(SdkType.SWFOBJECT); + FileUtils.copyDirectory(swfObjectRoot, sdkRoot); + + // In order to compile some of the themes, we need to download a + // playerglobal version. + logger.info("In order to convert some of the skins in the Apache Flex SDK, " + + "a Flash SDK has to be downloaded."); + File flashSdkRoot = downloadRetriever.retrieve(SdkType.FLASH, "10.2"); + FileUtils.copyDirectory(flashSdkRoot, sdkRoot); + + // Convert the FDK itself. + FlexConverter converter = new FlexConverter(sdkRoot, localRepoBaseDir); + converter.convert(); + + // Convert the wrapper. + WrapperConverter wrapperConverter = new WrapperConverter(sdkRoot, localRepoBaseDir); + wrapperConverter.convert(); + } catch (Throwable ce) { + throw new MavenExecutionException( + "Caught exception while downloading and converting artifact.", ce); + } + logger.info(" - Finished installing Apache Flex SDK " + version); + } + + protected void initFlash(String version) throws MavenExecutionException { + logger.info("==========================================================="); + logger.info(" - Installing Adobe Flash SDK " + version); + try { + File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir()); + DownloadRetriever downloadRetriever = new DownloadRetriever(); + File sdkRoot = downloadRetriever.retrieve(SdkType.FLASH, version); + FlashConverter converter = new FlashConverter(sdkRoot, localRepoBaseDir); + converter.convert(); + } catch (Throwable ce) { + throw new MavenExecutionException( + "Caught exception while downloading and converting artifact.", ce); + } + logger.info(" - Finished installing Adobe Flash SDK " + version); + } + + protected void initAir(String version) throws MavenExecutionException { + logger.info("==========================================================="); + logger.info(" - Installing Adobe AIR SDK " + version); + try { + File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir()); + DownloadRetriever downloadRetriever = new DownloadRetriever(); + File sdkRoot = downloadRetriever.retrieve(SdkType.AIR, version, PlatformType.getCurrent()); + AirConverter converter = new AirConverter(sdkRoot, localRepoBaseDir); + converter.convert(); + } catch (Throwable ce) { + throw new MavenExecutionException( + "Caught exception while downloading and converting artifact.", ce); + } + logger.info(" - Finished installing Adobe AIR SDK " + version); + } + + protected void initFontkit() throws MavenExecutionException { + logger.info("==========================================================="); + logger.info(" - Installing Adobe Fontkit libraries"); + try { + File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir()); + DownloadRetriever downloadRetriever = new DownloadRetriever(); + File sdkRoot = downloadRetriever.retrieve(SdkType.FONTKIT); + FontkitConverter converter = new FontkitConverter(sdkRoot, localRepoBaseDir); + converter.convert(); + } catch (Throwable ce) { + throw new MavenExecutionException( + "Caught exception while downloading and converting artifact.", ce); + } + logger.info(" - Finished installing Adobe Fontkit libraries"); + } + + + protected void showFlexSplashScreen() { + logger.info(" \n" + + " `,;':, :';;; \n" + + " `:;''';' `++'';;, \n" + + " :;'''++;' .+'+''';;;\n" + + " : ;'''++++'' ,';+++''';'\n" + + " ,. `, ,. ..: , `, `'''+++##;'', ;;'+#+++''''\n" + + " ; ; ; ;; ;`: :,: ; ; ;'+++; #;;;;;:::;;;;+ +++'':\n" + + " ; ; : ;; ;., : : ;. ;;++# ';;;;;;;;;;+ .+++; \n" + + " `;: :; `;: :;: , :;` +;+# ,;;;:::::;: ;#+', \n" + + " ;++++:'++ : ;+,; ++;# +;::::::; ,+;;: \n" + + " ++++++,'++ `++' +'''` ;::::::, +:;;: \n" + + " `+++. '++ ++++++ +++ +++ ''''' ;::::: :;;;; \n" + + " +++` '++ ++++++++ +++` `++: :'';;; ;::` ::::: \n" + + " +++ '++ +++' :++: +++ +++ ;;;;;' :::::: \n" + + " +++ '++ +++ ++' `+++++` ;;;;;;: .:::::` \n" + + " +++++++ '++ +++:::+++. +++++ ;;;;;;; ,::::: \n" + + " +++++++ '++ +++++++++ :+++' ;;;;;;; ,::::: \n" + + " +++''' '++ +++;;;:` +++++ ;;;;;;` ::::::. \n" + + " +++ '++ +++ +++ +++ ;;;;;: :::::: \n" + + " +++ :++. ++++ ` :++, ,++; ''';;. `..: ::::;` \n" + + " +++ ++' +++++++ +++ +++ :'''; ,,,,,: ;;;;; \n" + + " ;++` +++ ++++++ +++ +++ .+';+ :,,,,,,: `';;; \n" + + " ++' `+''' ::,,,,,::: ';;' \n" + + " :++ #;'' +:::,,,:::: .'':; \n" + + " ';;'' ::::::::::::' ,';;:.\n" + + " ;;;;''`;+;;::` .::;;'.,';;;;:\n" + + " `::;;;''':;; `;;;'';;;;;;\n" + + " :::;;;'';: ;;';;;;;:;\n" + + " ,:::;;;', ',;;;;::`\n" + + " .:::;:. ;:;;::: \n" + + " ::;, `,;;` \n"); + flexSplashScreenShown = true; + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/pom.xml b/flex-maven-tools/mavenizer/pom.xml new file mode 100644 index 0000000..e5317f6 --- /dev/null +++ b/flex-maven-tools/mavenizer/pom.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>16</version> + </parent> + + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>apache-flex-sdk-converter</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <properties> + <mavenVersion>3.1.1</mavenVersion> + <aetherVersion>0.9.0.M4</aetherVersion> + <wagonVersion>2.2</wagonVersion> + </properties> + + <mailingLists> + <mailingList> + <name>Apache Flex User List</name> + <subscribe>[email protected]</subscribe> + <unsubscribe>[email protected]</unsubscribe> + <post>[email protected]</post> + <archive> + http://mail-archives.apache.org/mod_mbox/flex-users/ + </archive> + </mailingList> + </mailingLists> + + <scm> + <connection>scm:git:https://git-wip-us.apache.org/repos/asf/flex-utilities.git</connection> + <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/flex-utilities.git</developerConnection> + <url>https://git-wip-us.apache.org/repos/asf/flex-utilities.git</url> + <tag>HEAD</tag> + </scm> + + <modules> + <module>retrievers</module> + <module>converters</module> + <module>deployers</module> + <module>cli</module> + <module>maven-extension</module> + </modules> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/pom.xml ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/pom.xml b/flex-maven-tools/mavenizer/retrievers/base/pom.xml new file mode 100644 index 0000000..ace86c6 --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.utilities.converter</groupId> + <artifactId>retrievers</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>base-retriever</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <powermock.version>1.6.2</powermock.version> + <junit.version>4.11</junit.version> + </properties> + + <dependencies> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <version>1.8.1</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.3.2</version> + </dependency> + + <!--TEST--> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>pl.pragmatists</groupId> + <artifactId>JUnitParams</artifactId> + <version>1.0.4</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/BaseRetriever.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/BaseRetriever.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/BaseRetriever.java new file mode 100644 index 0000000..514ed2e --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/BaseRetriever.java @@ -0,0 +1,116 @@ +/* + * 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.flex.utilities.converter.retrievers; + +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveException; +import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.archivers.ArchiveStreamFactory; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.apache.commons.compress.utils.CountingInputStream; +import org.apache.flex.utilities.converter.retrievers.exceptions.RetrieverException; +import org.apache.flex.utilities.converter.retrievers.utils.ProgressBar; + +import java.io.*; + +/** + * Created by cdutz on 18.05.2014. + */ +public abstract class BaseRetriever implements Retriever { + + public static final int KILOBYTE = 1024; + public static final int MEGABYTE = KILOBYTE * 1024; + public static final int BUFFER_MAX = MEGABYTE; + + protected void unpack(File inputArchive, File targetDirectory) throws RetrieverException { + if (!targetDirectory.mkdirs()) { + throw new RetrieverException( + "Unable to create extraction directory " + targetDirectory.getAbsolutePath()); + } + + ArchiveInputStream archiveInputStream = null; + ArchiveEntry entry; + try { + + final CountingInputStream inputStream = new CountingInputStream(new FileInputStream(inputArchive)); + + final long inputFileSize = inputArchive.length(); + + if(inputArchive.getName().endsWith(".tbz2")) { + archiveInputStream = new TarArchiveInputStream( + new BZip2CompressorInputStream(inputStream)); + } else { + archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream( + new BufferedInputStream(inputStream)); + } + + final ProgressBar progressBar = new ProgressBar(inputFileSize); + while ((entry = archiveInputStream.getNextEntry()) != null) { + final File outputFile = new File(targetDirectory, entry.getName()); + + // Entry is a directory. + if (entry.isDirectory()) { + if (!outputFile.exists()) { + if(!outputFile.mkdirs()) { + throw new RetrieverException( + "Could not create output directory " + outputFile.getAbsolutePath()); + } + } + } + + // Entry is a file. + else { + final byte[] data = new byte[BUFFER_MAX]; + final FileOutputStream fos = new FileOutputStream(outputFile); + BufferedOutputStream dest = null; + try { + dest = new BufferedOutputStream(fos, BUFFER_MAX); + + int count; + while ((count = archiveInputStream.read(data, 0, BUFFER_MAX)) != -1) { + dest.write(data, 0, count); + progressBar.updateProgress(inputStream.getBytesRead()); + } + } finally { + if(dest != null) { + dest.flush(); + dest.close(); + } + } + } + + progressBar.updateProgress(inputStream.getBytesRead()); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ArchiveException e) { + e.printStackTrace(); + } finally { + if(archiveInputStream != null) { + try { + archiveInputStream.close(); + } catch(Exception e) { + // Ignore... + } + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/Retriever.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/Retriever.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/Retriever.java new file mode 100644 index 0000000..ee863e3 --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/Retriever.java @@ -0,0 +1,32 @@ +/* + * 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.flex.utilities.converter.retrievers; + +import org.apache.flex.utilities.converter.retrievers.exceptions.RetrieverException; +import org.apache.flex.utilities.converter.retrievers.types.PlatformType; +import org.apache.flex.utilities.converter.retrievers.types.SdkType; + +import java.io.File; + +/** + * Created by cdutz on 18.05.2014. + */ +public interface Retriever { + + File retrieve(SdkType sdkType, String version, PlatformType platformType) throws RetrieverException; + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/exceptions/RetrieverException.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/exceptions/RetrieverException.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/exceptions/RetrieverException.java new file mode 100644 index 0000000..bfb708b --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/exceptions/RetrieverException.java @@ -0,0 +1,32 @@ +/* + * 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.flex.utilities.converter.retrievers.exceptions; + +/** + * Created by cdutz on 07.05.2014. + */ +public class RetrieverException extends Exception { + + public RetrieverException(String message) { + super(message); + } + + public RetrieverException(String message, Throwable cause) { + super(message, cause); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java new file mode 100644 index 0000000..d7320d4 --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java @@ -0,0 +1,49 @@ +/* + * 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.flex.utilities.converter.retrievers.types; + +import org.apache.commons.lang3.SystemUtils; + +/** + * Created by cdutz on 18.05.2014. + */ +public enum PlatformType { + + WINDOWS, + LINUX, + MAC; + + public static PlatformType getCurrent() throws Exception { + PlatformType platformType = null; + + if (SystemUtils.IS_OS_WINDOWS) + { + platformType = PlatformType.WINDOWS; + } + else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) + { + platformType = PlatformType.MAC; + } + else if (SystemUtils.IS_OS_UNIX) + { + platformType = PlatformType.LINUX; + } + else throw new Exception("Unsupported OS."); + + return platformType; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java new file mode 100644 index 0000000..f8b3024 --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java @@ -0,0 +1,30 @@ +/* + * 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.flex.utilities.converter.retrievers.types; + +/** + * Created by cdutz on 18.05.2014. + */ +public enum SdkType { + + FLEX, + FLASH, + AIR, + FONTKIT, + SWFOBJECT + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/657a7def/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java ---------------------------------------------------------------------- diff --git a/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java new file mode 100644 index 0000000..c15d26b --- /dev/null +++ b/flex-maven-tools/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java @@ -0,0 +1,47 @@ +/* + * 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.flex.utilities.converter.retrievers.utils; + +import org.apache.commons.lang3.StringUtils; + +/** + * Created by cdutz on 24.05.2014. + */ +public class ProgressBar { + + protected long total; + + public ProgressBar(long total) { + this.total = total; + drawOutput(0l); + } + + public void updateProgress(long current) { + drawOutput(current); + } + + protected void drawOutput(long current) { + final int transferredPercent = (int) Math.round( + ((double) current / (double) total) * (double) 100); + final int segmentsTransferred = transferredPercent / 2; + final int segmentsRest = 50 - segmentsTransferred; + System.out.print("\r" + String.format(" %3d", transferredPercent) + "% [" + + StringUtils.repeat("=", segmentsTransferred) + + ((segmentsRest > 0) ? ">" + StringUtils.repeat(" ", segmentsRest - 1) : "") + "] "); + } + +}
