[259580] Babel Language Pack Build Tool initial check-in, with confirmation from the IP team https://dev.eclipse.org/ipzilla/show_bug.cgi?id=3082#c11
diff --git a/org.eclipse.babel.build.ant/.classpath b/org.eclipse.babel.build.ant/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/org.eclipse.babel.build.ant/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/org.eclipse.babel.build.ant/.project b/org.eclipse.babel.build.ant/.project new file mode 100644 index 0000000..a3ddeae --- /dev/null +++ b/org.eclipse.babel.build.ant/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.babel.build.ant</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/org.eclipse.babel.build.ant/META-INF/MANIFEST.MF b/org.eclipse.babel.build.ant/META-INF/MANIFEST.MF new file mode 100644 index 0000000..83eb7f3 --- /dev/null +++ b/org.eclipse.babel.build.ant/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Babel Ant Plug-in +Bundle-SymbolicName: org.eclipse.babel.build.ant +Bundle-Version: 1.0.0 +Bundle-Vendor: Eclipse.org +Require-Bundle: org.junit, + org.apache.ant, + org.eclipse.babel.build.core
diff --git a/org.eclipse.babel.build.ant/build.properties b/org.eclipse.babel.build.ant/build.properties new file mode 100644 index 0000000..06f6d0e --- /dev/null +++ b/org.eclipse.babel.build.ant/build.properties
@@ -0,0 +1,14 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .
diff --git a/org.eclipse.babel.build.ant/build.xml b/org.eclipse.babel.build.ant/build.xml new file mode 100644 index 0000000..d517fb4 --- /dev/null +++ b/org.eclipse.babel.build.ant/build.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="BuildAnt" default="dist"> + <description>description</description> + + <property name="dir.src" value="src" /> + <property name="dir.build" value="build" /> + <property name="dir.dist" value="dist" /> + <property name="dir.lib" value="lib" /> + <property name="dir.junit" value="junit" /> + <property name="dir.core" value="../org.eclipse.babel.build" /> + <property name="dir.doc" value="doc" /> + + <path id="lib.classpath"> + <fileset dir="${dir.lib}"> + <include name="*.jar" /> + </fileset> + </path> + + <path id="core.classpath"> + <fileset dir="${dir.core}/dist"> + <include name="*.jar" /> + </fileset> + </path> + + <target name="deps"> + <subant buildpath="${dir.core}/build.xml" target="dist" /> + </target> + + <target name="prepare"> + <mkdir dir="${dir.build}" /> + <mkdir dir="${dir.dist}" /> + <mkdir dir="${dir.junit}" /> + </target> + + <target name="clean" description="Delete generated files"> + <delete dir="${dir.build}" /> + <delete dir="${dir.dist}" /> + <delete dir="${dir.junit}" /> + <delete file="cobertura.ser" /> + </target> + + <target name="compile" depends="deps,prepare" description="Compile project files"> + <javac destdir="${dir.build}" debug="true" source="1.5" target="1.5"> + <src path="${dir.src}" /> + <classpath refid="lib.classpath" /> + <classpath refid="core.classpath" /> + </javac> + </target> + + <target name="deps-jar" depends="compile"> + <jar jarfile="${dir.dist}/azure-ant-deps.jar" basedir="${dir.build}"> + <fileset dir="${dir.core}/build" includes="**/*" /> + </jar> + </target> + + <target name="dist" depends="compile,deps-jar" description="Package project files for distribution"> + <jar jarfile="${dir.dist}/build-ant.jar" basedir="${dir.build}" /> + </target> + + <target name="junit"> + <junit printsummary="on" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true"> + <classpath refid="lib.classpath" /> + <classpath refid="core.classpath" /> + <formatter type="xml" usefile="true" /> + <batchtest fork="yes" todir="${dir.junit}"> + <fileset dir="${dir.src}"> + <include name="**/*Test*.java"/> + </fileset> + </batchtest> + </junit> + <fail if="tests.failed" /> + </target> + + <target name="javadoc" description="Generates javadoc for the project"> + <javadoc sourcepath="${dir.src}" + packagenames="org.eclipse.babel.build.ant" + destdir="${dir.doc}/javadoc" + access="public" + classpathref="lib.classpath" + excludepackagenames="org.eclipse.babel.build.ant.test.*" + > + <classpath refid="core.classpath"/> + </javadoc> + </target> +</project>
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/BuildTask.java b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/BuildTask.java new file mode 100644 index 0000000..00c8876 --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/BuildTask.java
@@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ant; + +import java.io.File; +import java.util.LinkedList; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LazyConfiguration; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.languagepack.LanguagePack; + + +/** + * Task used to execute the tool from an ant build script. + * Builds a {@link org.eclipse.babel.build.core.LazyConfiguration} then + * passes it to {@link org.eclipse.babel.build.core.languagepack.LanguagePack}. + * + * <p>All methods are called reflectively by ant depending on attributes + * supplied by the user in the build file. For example: + * <pre> + * <nlsbuild + * eclipse="/tmp/eclipse.zip" + * translations="/tmp/translations" + * locales="en,zh-TW" + * /> + * </pre> + * + * Would result in the following calls: + * <pre> + * BuildTask nlsbuild = new BuildTask(); + * nlsbuild.setEclipse("/tmp/eclipse.zip"); + * nlsbuild.setTranslations("/tmp/translations"); + * nlsbuild.setLocales("en,zh_TW"); + * nlsbuild.execute(); + * </pre> + */ + +public class BuildTask extends Task { + public static class Exclude{ + String fileType = ""; + + public void setFileType(String fileType){ + this.fileType = fileType; + } + } + + public static class Excludes{ + List<Exclude> fileTypes = new LinkedList<Exclude>(); + + public Exclude createExclude(){ + Exclude exclude = new Exclude(); + fileTypes.add(exclude); + return exclude; + } + } + + private final LazyConfiguration config = new LazyConfiguration(); + private CoverageReport coverageReport = new CoverageReport(); + private Excludes excludes = new Excludes(); + + + /** + * Constructs a new BuildTask. Required by ant. + */ + public BuildTask(){ + super(); + } + + /** + * Sets the working directory for the build. Called by ant. + * + * @param file Path to the working directory. + */ + public void setWorkingDirectory(String file){ + config.setWorkingDirectory(new File(file)); + } + + /** + * Sets the eclipse archive to be used. Called by ant. + * + * @param file Path to the Eclipse Archive. + */ + public void setEclipse(String file){ + config.setArchiveRoot(new File(file)); + } + + public void setLongReport(boolean longReport){ + config.setLongReport(longReport); + } + + public void setIncludeXmlReport(boolean xml){ + config.setIncludeXmlReport(xml); + } + + /** + * Sets the locales to be used. Called by ant. + * + * @param specifier List of locales to be used (of the format "en,zh_TW"). + */ + public void setLocales(String specifier){ + config.addLocales(Configuration.helper.getLocales(specifier)); + config.addLocaleGroups(Configuration.helper.getLocaleGroups(specifier)); + } + + /** + * Sets the translations to be used. Called by ant. + * + * @param file Path to the translations. + */ + public void setTranslations(String file){ + config.setTranslationsRoot(new File(file)); + } + + /** + * Sets whether to include pseudo-translations in the generated + * translation catalog. Called by ant. + * + * @param include Whether to include pseudo-translations. + */ + public void setIncludePseudoTranslations(boolean include){ + config.setIncludePseudoTranslations(include); + } + + public CoverageReport createCoverageReport(){ + coverageReport = new CoverageReport(); + return coverageReport; + } + + public Excludes createExcludes(){ + excludes = new Excludes(); + return excludes; + } + + /** + * Build the translation catalog. Called by ant. + */ + @Override + public void execute() throws BuildException { + try { + for(Ignore ignore : coverageReport.ignores()){ + config.addFilter(ignore.toFilter()); + } + + for(Exclude exclude : excludes.fileTypes){ + config.addExclude(exclude.fileType); + + } + + config.validate(); + System.out.println("Parsing language pack..."); + LanguagePack languagePack = new LanguagePack(config); + LanguagePackCoverageReport coverage = languagePack.generate(); + System.out.println("Printing coverage report..."); + Configuration.helper.printLanguagePackResult(config, coverage); + System.out.println("DONE"); + } catch (Exception e) { + System.err.println(e.getMessage()); + throw new BuildException(e); + } + } +}
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/CoverageReport.java b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/CoverageReport.java new file mode 100644 index 0000000..c2b4474 --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/CoverageReport.java
@@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ant; + +import java.util.LinkedList; +import java.util.List; + +public class CoverageReport { + private final List<Ignore> ignores = new LinkedList<Ignore>(); + + public Ignore createIgnore(){ + Ignore ignore = new Ignore(); + ignores.add(ignore); + return ignore; + } + + public List<Ignore> ignores(){ + return ignores; + } + +}
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/Ignore.java b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/Ignore.java new file mode 100644 index 0000000..7f38337 --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/Ignore.java
@@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ant; + +import org.eclipse.babel.build.core.Filter; + +public class Ignore { + private String pattern; + + public void setPattern(String pattern){ + this.pattern = pattern; + } + + public Filter toFilter(){ + return new Filter(pattern); + } +}
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/ResourceFilter.java b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/ResourceFilter.java new file mode 100644 index 0000000..c48b7ab --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/ResourceFilter.java
@@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ant; + +public class ResourceFilter { + +}
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/package.html b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/package.html new file mode 100644 index 0000000..a8453cc --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/package.html
@@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body> +Provides an Ant interface to the NL Build tool. +</body> +</html>
diff --git a/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/test/TestBuildTask.java b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/test/TestBuildTask.java new file mode 100644 index 0000000..a765c68 --- /dev/null +++ b/org.eclipse.babel.build.ant/src/org/eclipse/babel/build/ant/test/TestBuildTask.java
@@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ant.test; + +import junit.framework.TestCase; + +import org.eclipse.babel.build.ant.BuildTask; + +public class TestBuildTask extends TestCase{ + public void testBuildTask() throws Exception { + BuildTask buildTask = new BuildTask(); + buildTask.setWorkingDirectory("/work/nls/w"); + buildTask.setEclipse("/work/nls/testing/eclipse-SDK-3.4M5-win32.zip"); + buildTask + .setTranslations("/Users/aaron/Desktop/nls/IES_3.3/piiDocTransDir"); + buildTask.setLocales("gr1"); + buildTask.createCoverageReport().createIgnore().setPattern( + "^META-INF/.*"); + buildTask.execute(); + } + + public void testBuildTask_missingEclipse() throws Exception { + BuildTask buildTask = new BuildTask(); + buildTask.setWorkingDirectory("/work/nls/w"); + buildTask.setEclipse("/this/path/doesnt/exist"); + buildTask + .setTranslations("/Users/aaron/Desktop/nls/IES_3.3/piiDocTransDir"); + buildTask.setLocales("gr1"); + buildTask.createCoverageReport().createIgnore().setPattern( + "^META-INF/.*"); + buildTask.execute(); + } +}
diff --git a/org.eclipse.babel.build.ant/test_buildfiles/test_build.xml b/org.eclipse.babel.build.ant/test_buildfiles/test_build.xml new file mode 100644 index 0000000..5da9220 --- /dev/null +++ b/org.eclipse.babel.build.ant/test_buildfiles/test_build.xml
@@ -0,0 +1,12 @@ +<project name="test" default="main"> + <taskdef name="nlsbuild" classname="org.eclipse.babel.build.ant.BuildTask" /> + + <target name="main"> + <nlsbuild + eclipse="/work/nls/testing/eclipse-SDK-3.4M5-win32.zip" + translations="/work/nls/piiDocTransDir/gr1" + workingDirectory="/work/nls/w"> + + </nlsbuild> + </target> +</project>
diff --git a/org.eclipse.babel.build.ant/test_buildfiles/test_build_invalid_language_pack.xml b/org.eclipse.babel.build.ant/test_buildfiles/test_build_invalid_language_pack.xml new file mode 100644 index 0000000..15149ee --- /dev/null +++ b/org.eclipse.babel.build.ant/test_buildfiles/test_build_invalid_language_pack.xml
@@ -0,0 +1,20 @@ +<project name="test" default="main"> + <taskdef name="nlsbuild" classname="org.eclipse.babel.build.ant.BuildTask" /> + + <target name="main"> + <nlsbuild + eclipse="/work/nls/testing/eclipse-SDK-3.4M5-win32.zip" + translations="/Users/aaron/Desktop/nls/IES_3.3/piiDocTransDir" + workingDirectory="/work/nls/w" + locales="fr,en"> + + <coverageReport> + <ignore pattern="^META-INF.*" /> + </coverageReport> + + <excludes> + <exclude filetype=".java" /> + </excludes> + </nlsbuild> + </target> +</project> \ No newline at end of file
diff --git a/org.eclipse.babel.build.ant/test_buildfiles/test_build_longreport.xml b/org.eclipse.babel.build.ant/test_buildfiles/test_build_longreport.xml new file mode 100644 index 0000000..f5e461d --- /dev/null +++ b/org.eclipse.babel.build.ant/test_buildfiles/test_build_longreport.xml
@@ -0,0 +1,22 @@ +<project name="test" default="main"> + <taskdef name="nlsbuild" classname="org.eclipse.babel.build.ant.BuildTask" /> + + <target name="main"> + <nlsbuild + eclipse="/work/nls/testing/eclipse-SDK-3.4M5-win32.zip" + translations="/Users/aaron/Desktop/nls/IES_3.3/piiDocTransDir" + workingDirectory="/work/nls/w" + locales="fr,ar" + longReport="true" + includeXmlReport="true"> + + <coverageReport> + <ignore pattern="^META-INF.*" /> + </coverageReport> + + <excludes> + <exclude filetype=".java" /> + </excludes> + </nlsbuild> + </target> +</project> \ No newline at end of file
diff --git a/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_eclipse.xml b/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_eclipse.xml new file mode 100644 index 0000000..1b75a09 --- /dev/null +++ b/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_eclipse.xml
@@ -0,0 +1,20 @@ +<project name="test" default="main"> + <taskdef name="nlsbuild" classname="org.eclipse.babel.build.ant.BuildTask" /> + + <target name="main"> + <nlsbuild + eclipse="/this/path/doesnt/exist.zip" + translations="/Users/aaron/Desktop/nls/IES_3.3/piiDocTransDir" + workingDirectory="/work/nls/w" + locales="gr1"> + + <coverageReport> + <ignore pattern="^META-INF.*" /> + </coverageReport> + + <excludes> + <exclude filetype=".java" /> + </excludes> + </nlsbuild> + </target> +</project>
diff --git a/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_translations.xml b/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_translations.xml new file mode 100644 index 0000000..b265f7e --- /dev/null +++ b/org.eclipse.babel.build.ant/test_buildfiles/test_build_missing_translations.xml
@@ -0,0 +1,20 @@ +<project name="test" default="main"> + <taskdef name="nlsbuild" classname="org.eclipse.babel.build.ant.BuildTask" /> + + <target name="main"> + <nlsbuild + eclipse="/work/nls/testing/eclipse-SDK-3.4M5-win32.zip" + translations="/this/path/does/not/exist" + workingDirectory="/work/nls/w" + locales="gr1"> + + <coverageReport> + <ignore pattern="^META-INF.*" /> + </coverageReport> + + <excludes> + <exclude filetype=".java" /> + </excludes> + </nlsbuild> + </target> +</project>
diff --git a/org.eclipse.babel.build.core/.classpath b/org.eclipse.babel.build.core/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/org.eclipse.babel.build.core/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/org.eclipse.babel.build.core/.project b/org.eclipse.babel.build.core/.project new file mode 100644 index 0000000..fc20295 --- /dev/null +++ b/org.eclipse.babel.build.core/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.babel.build.core</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/org.eclipse.babel.build.core/META-INF/MANIFEST.MF b/org.eclipse.babel.build.core/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ee2f66a --- /dev/null +++ b/org.eclipse.babel.build.core/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Babel Build Core Plug-in +Bundle-SymbolicName: org.eclipse.babel.build.core +Bundle-Version: 1.0.0 +Bundle-Vendor: Eclipse.org +Export-Package: org.eclipse.babel.build.core, + org.eclipse.babel.build.core.coverage, + org.eclipse.babel.build.core.eclipsetarget, + org.eclipse.babel.build.core.exceptions, + org.eclipse.babel.build.core.languagepack, + org.eclipse.babel.build.core.translationcatalogue
diff --git a/org.eclipse.babel.build.core/build.properties b/org.eclipse.babel.build.core/build.properties new file mode 100644 index 0000000..06f6d0e --- /dev/null +++ b/org.eclipse.babel.build.core/build.properties
@@ -0,0 +1,14 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .
diff --git a/org.eclipse.babel.build.core/build.xml b/org.eclipse.babel.build.core/build.xml new file mode 100644 index 0000000..83f8234 --- /dev/null +++ b/org.eclipse.babel.build.core/build.xml
@@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="Built Tool Core" default="dist"> + <description>description</description> + + <property name="dir.src" value="src" /> + <property name="dir.build" value="build" /> + <property name="dir.dist" value="dist" /> + <property name="dir.lib" value="lib" /> + <property name="dir.junit" value="junit" /> + <property name="dir.doc" value="doc" /> + + <path id="lib.classpath"> + <fileset dir="${dir.lib}"> + <include name="*.jar" /> + </fileset> + </path> + + <target name="prepare"> + <mkdir dir="${dir.build}" /> + <mkdir dir="${dir.dist}" /> + <mkdir dir="${dir.junit}" /> + <mkdir dir="${dir.doc}" /> + </target> + + <target name="clean" description="Delete generated files"> + <delete dir="${dir.build}" /> + <delete dir="${dir.dist}" /> + <delete dir="${dir.junit}" /> + <delete file="cobertura.ser" /> + <delete dir="${dir.doc}" /> + </target> + + <target name="compile" depends="prepare,copy-resources" description="Compile project files"> + <javac destdir="${dir.build}" debug="true" srcdir="${dir.src}" source="1.5" target="1.5"> + <classpath refid="lib.classpath" /> + </javac> + </target> + + <target name="dist" depends="compile" description="Package project files for distribution"> + <jar jarfile="${dir.dist}/azure-cli.jar" basedir="${dir.build}"> + <manifest> + <attribute name="Main-Class" value="org.eclipse.babel.build.core.Main" /> + </manifest> + </jar> + </target> + + <target name="junit" depends="compile"> + <junit printsummary="on" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true"> + <classpath refid="lib.classpath" /> + <classpath location="${dir.build}" /> + <formatter type="xml" usefile="true" /> + <batchtest fork="yes" todir="${dir.junit}"> + <fileset dir="${dir.src}"> + <include name="**/*Test*.java"/> + </fileset> + </batchtest> + </junit> + <fail if="tests.failed" /> + </target> + + <target name="copy-resources"> + <copy todir="${dir.build}"> + <fileset dir="${dir.src}" excludes="**/*.java"/> + </copy> + </target> + + <target name="javadoc" description="Generates javadoc for the project"> + <javadoc sourcepath="${dir.src}" + packagenames="org.eclipse.babel.build.core.xml,org.eclipse.babel.build.core" + destdir="${dir.doc}/javadoc" + access="public" + classpathref="lib.classpath" + excludepackagenames="org.eclipse.babel.buld.core.test.*" + /> + </target> +</project>
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/annotations/Requirement.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/annotations/Requirement.java new file mode 100644 index 0000000..92b9e61 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/annotations/Requirement.java
@@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.annotations; + +public @interface Requirement { + int[] id(); +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/CommandLineConfiguration.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/CommandLineConfiguration.java new file mode 100644 index 0000000..91a1ffa --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/CommandLineConfiguration.java
@@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.io.File; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; +import org.eclipse.babel.build.core.exceptions.MissingLocationException; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + + +/** + * Configuration which derives it's parameters from parsing a command line. + */ +public class CommandLineConfiguration implements Configuration { + public class Times{ + public long eclipseInstallPopulation; + public long translationCataloguePopulation; + public long languagePackGeneration; + } + + private EclipseTarget eclipseInstall = null; + private TranslationCatalogue translationCatalogue = null; + private final Set<LocaleProxy> locales; + private final Set<LocaleGroup> localeGroups; + private final File workingDirectory; + private final File eclipseRoot; + private final File translationsRoot; + final Times times = new Times(); + private File report; + private final Set<String> excludeList; + private List<Filter> reportFilters; + + private final boolean includeXmlReport; + private final boolean longReport; + private String localeExtension; + + final static String TOKEN = Messages.getString("Characters_locale_token"); //$NON-NLS-1$ + + public CommandLineConfiguration(String... args) { + Options opts = new Options( + "--working-directory=", "--locales=", + "--translation-archive=!", "--eclipse-archive=!", + "--coverage-report=", "--exclude-list=", + "--report-ignore-list=", "--xml", "--long-report" + ).parse(args); + + Set<LocaleProxy> locales = helper.getLocales(opts.get("--locales")); + Set<LocaleGroup> localeGroups = helper.getLocaleGroups(opts.get("--locales")); + Set<String> excludeList = getExcludeList(opts.get("--exclude-list")); + + this.eclipseRoot = new File(opts.get("--eclipse-archive")); + this.locales = locales; + this.localeGroups = localeGroups; + this.translationsRoot = new File(opts.get("--translation-archive")); + this.workingDirectory = new File(opts.get("--working-directory", ".")); + + this.excludeList = excludeList; + report = new File(opts.get("--coverage-report", new File(workingDirectory, "coverage.xml").getAbsolutePath())); + + if(!report.isAbsolute()){ + report = new File(workingDirectory, report.getPath()); + } + + reportFilters = buildFilterList(opts.get("--report-ignore-list", "")); + + includeXmlReport = opts.isSet("--xml"); + longReport = opts.isSet("--long-report"); + + localeExtension = ""; + if (this.locales.size() == 1 && this.localeGroups.isEmpty()) { + LocaleProxy singleLocale = this.locales.iterator().next(); + localeExtension += Messages.getString("Characters_underscore") + singleLocale.getName(); //$NON-NLS-1$ + } + } + + private List<Filter> buildFilterList(String specifier){ + List<Filter> filters = new LinkedList<Filter>(); + + for(String filter : specifier.split(" ")){ + filters.add(new Filter(filter)); + } + + return filters; + } + + public EclipseTarget eclipseInstall() { + try { + if (eclipseInstall == null){ + long startEclipseArchivePopulation = System.currentTimeMillis(); + eclipseInstall = new EclipseTarget(eclipseRoot, this.excludeList); + System.out.println(Messages.getString("Messages_parsing_eclipse_target")); //$NON-NLS-1$ + eclipseInstall.populatePlugins(); + System.out.println("Plugins: " + eclipseInstall.getPlugins().size() + " Features: " + eclipseInstall.getFeatures().size()); //$NON-NLS-1$ $NON-NLS-2$ + times.eclipseInstallPopulation = System.currentTimeMillis() - startEclipseArchivePopulation; + } + } catch (InvalidLocationException i) { + System.out.println( Messages.getString("Error_invalid_eclipse_target") ); //$NON-NLS-1$ + System.exit(0); + } catch (MissingLocationException m) { + System.out.println( Messages.getString("Error_missing_eclipse_target") ); //$NON-NLS-1$ + System.exit(0); + } catch (InvalidFilenameException i) { + System.out.println( Messages.getString("Error_invalid_eclipse_target_name") ); //$NON-NLS-1$ + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.out.println( Messages.getString("Error_eclipse_target") ); //$NON-NLS-1$ + System.exit(0); + } + return eclipseInstall; + } + + public Range compatibilityRange() { + // TODO Auto-generated method stub + return null; + } + + public List<Filter> filters() { + return reportFilters; + } + + public boolean includePseudoTranslations() { + // TODO Auto-generated method stub + return false; + } + + public boolean includeResource(PluginProxy plugin, ResourceProxy resource) { + for(Filter filter : reportFilters){ + if(filter.matches(plugin, resource)){ + return filter.isInclusive(); + } + } + return true; + } + + public Set<LocaleProxy> locales() { + return locales; + } + + + public Set<LocaleGroup> localeGroups() { + return localeGroups; + } + + public Set<String> excludeList() { + return excludeList; + } + + public File reportLocation() { + return report; + } + + public Date timestamp() { + return new Date(); + } + + public TranslationCatalogue translations() { + if (translationCatalogue == null){ + try { + if (localeGroups.isEmpty()) { + translationCatalogue = new TranslationCatalogue(translationsRoot, locales); + } else { + locales.clear(); + translationCatalogue = new TranslationCatalogue(translationsRoot, localeGroups); + locales.addAll(translationCatalogue.getAllLocales()); + } + } catch (MissingLocationException m) { + System.out.println( Messages.getString("Error_missing_translation_catalogue") ); //$NON-NLS-1$ + System.exit(0); + } catch (InvalidLocationException i) { + System.out.println( i.getMessage() ); + System.exit(0); + } catch (InvalidFilenameException i) { + System.out.println( Messages.getString("Error_invalid_translation_catalogue_name") ); //$NON-NLS-1$ + System.exit(0); + } + } + return translationCatalogue; + } + + public File workingDirectory() { + return workingDirectory; + } + + private static Set<String> getExcludeList(String specifier){ + Set<String> excludeList = new HashSet<String>(); + + if(null == specifier){ + return excludeList; + } + + for(String suffix : specifier.split( TOKEN )){ + excludeList.add(suffix); + } + + return excludeList; + } + + public void notifyProgress(String fragmentName) { + // TODO Auto-generated method stub + } + + public boolean includeXmlReport() { + return includeXmlReport; + } + + public boolean longReport() { + return longReport; + } + + public final String localeExtension() { + return localeExtension; + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Configuration.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Configuration.java new file mode 100644 index 0000000..c9d9258 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Configuration.java
@@ -0,0 +1,229 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.reports.CoverageReport; +import org.eclipse.babel.build.core.reports.HtmlCoverageReport; +import org.eclipse.babel.build.core.reports.XmlCoverageReport; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + + +/** + * Defines the parameters which configure a run of the tool. + */ +public interface Configuration { + public static class helper{ + /** + * This class should not be instantiated. + */ + private helper(){} + + /** + * Serializes a given configuration to an output stream so that it can be reused. + * + * @param out The output stream to which the configuration should be serialized. + */ + public static void serialize(OutputStream out){ + // TODO: stub + } + + /** + * Parses a stored configuration. + * + * @param in The input stream from which a configuration should be deserialized. + * @return The configuration obtained from parsing the provided input stream. + */ + public static Configuration parse(InputStream in){ + // TODO: stub + return null; + } + + public static Set<LocaleProxy> parseLocales(String specifier){ + if(null == specifier || "*".equals(specifier)){ + return LocaleProxy.ALL; + } + + Set<LocaleProxy> set = new HashSet<LocaleProxy>(); + for(String name : specifier.split(",")){ + set.add(new LocaleProxy(name)); + } + return set; + } + + public static void printCoverageReport(CoverageReport report, File file) throws Exception{ + + FileOutputStream out = new FileOutputStream(file); + try{ + report.render(out); + } finally { + out.close(); + } + } + + public static void printLanguagePackResult(final Configuration config, LanguagePackCoverageReport coverage) throws Exception { + XmlCoverageReport report = new XmlCoverageReport(config, coverage); + HtmlCoverageReport htmlReport = new HtmlCoverageReport(config, coverage); + + if(config.includeXmlReport()){ + printCoverageReport(report, config.reportLocation()); + } + + printCoverageReport(htmlReport, new File(config.reportLocation().getParent(), "coverage.html")); + } + + public static Set<LocaleProxy> getLocales(String specifier){ + if(null == specifier || LocaleGroup.GROUP_ALL.getName().equals(specifier)){ + return LocaleProxy.ALL; + } + + Set<LocaleProxy> locales = new HashSet<LocaleProxy>(); + for(String locale : specifier.split( CommandLineConfiguration.TOKEN )){ + if (! LocaleGroup.isValidGroupName(locale) && !LocaleGroup.isValidGroupFullName(locale)){ + locales.add(new LocaleProxy(locale)); + } + } + + return locales; + } + + public static Set<LocaleGroup> getLocaleGroups(String specifier){ + Set<LocaleGroup> set = new HashSet<LocaleGroup>(); + if(null == specifier) { + return set; + } + + if (LocaleGroup.GROUP_ALL.getName().equals(specifier)){ + set.add(LocaleGroup.GROUP_ALL); + } + + for(String token : specifier.split( CommandLineConfiguration.TOKEN )){ + if (LocaleGroup.isValidGroupName(token)) { + set.add(LocaleGroup.get(token)); + } + else if(LocaleGroup.isValidGroupFullName(token)) { + set.add(LocaleGroup.getByFullName(token)); + } + } + + return set; + } + } + + /** + * Retrieve the eclipse install for which the language pack should be generated. + * + * @return The eclipse install for which the language pack should be generated. + */ + public EclipseTarget eclipseInstall(); + + /** + * Retrieve the translations from which the translated resources should be retrieved. + * + * @return The translations from which the translated resources should be retrieved. + */ + public TranslationCatalogue translations(); + + /** + * Retrieve the timestamp to use in output files. + * + * @return Timestamp to use in output files. + */ + public Date timestamp(); + + /** + * Retrieve the working directory into which generated artifacts should be stored. + * + * @return The working directory into which generated artifacts should be stored. + */ + public File workingDirectory(); + + /** + * Retrieve whether or not to include pseudo-translations for missing strings in the generated language pack. + * + * @return Whether or not to include pseudo-translations for missing strings in the generated lanaguage pack. + */ + public boolean includePseudoTranslations(); + + /** + * Retrieve the range of Eclipse versions the generated lanaguage pack will be compatible with. + * + * @return The range of Eclipse versions the generated language pack will be compatible with. + */ + public Range compatibilityRange(); + + /** + * Retrieve the location of where the coverage report should be stored. + * + * @return The location to which the coverage report should be stored. + */ + public File reportLocation(); + + /** + * Queries the configuration as to whether a resource should be included in the coverage report. + * + * @param resouce The resource whose inclusion is at question. + * @return Whether or not the resource should be included in the coverage report. + */ + public boolean includeResource(PluginProxy plugin, ResourceProxy resouce); + + /** + * Retrieve the list of filters which specify which resources should be included in the coverage report. + * + * @return The list of filters used to select which resources should be included in the coverage report. + */ + public List<Filter> filters(); + + /** + * Retrieve the set of locales that should be included in the generated language pack. + * + * @return The set of locales that should be included in the generated language pack. + */ + public Set<LocaleProxy> locales(); + + /** + * Retrieve the locale groups that should be included in the generated language pack. + * + * @return The locale groups that should be included in the generated language pack. + */ + public Set<LocaleGroup> localeGroups(); + + /** + * Retrieve the list of filename suffixes that should be excluded when parsing the eclipse target. + * + * @return The list of filename suffixes that should be excluded when parsing the eclipse target. + */ + public Set<String> excludeList(); + + /** + * Provides notification regarding progress. + * + * @param fragmentName The name of the plugin/feature for which a fragement is being created. + */ + public void notifyProgress(String fragmentName); + + public boolean includeXmlReport(); + + public boolean longReport(); + + public String localeExtension(); +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Filter.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Filter.java new file mode 100644 index 0000000..acb4d8d --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Filter.java
@@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.util.regex.Pattern; + +public class Filter { + private final Pattern pattern; + private final String specifier; + + public Filter(String pattern) { + specifier = pattern; + this.pattern = Pattern.compile(pattern); + } + + public String getPattern(){ + return specifier; + } + + public boolean matches(PluginProxy plugin, ResourceProxy resource){ + String relativePath = resource.getRelativePath(); + boolean relative = pattern.matcher(relativePath).matches(); + boolean absolute = pattern.matcher(plugin.getName() + "/" + relativePath).matches(); + return relative || absolute; + } + + public boolean isInclusive(){ + return false; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LazyConfiguration.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LazyConfiguration.java new file mode 100644 index 0000000..a307495 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LazyConfiguration.java
@@ -0,0 +1,334 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.io.File; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + +/** + * Implements a configuration that can be built up incrementally. + * It has two states: + * <ul> + * <li>Unvalidated</li> + * <li>Validated</li> + * </ul> + * + * When it is initially created it is in the unvalidated state, in this state the setX, isValidated and validate methods may + * be called, but all other methods will throw an IllegalStateException. Once the validate method is called, the + * state of each field will be validated, and if all fields are valid, it will transition to the validated state. + * Otherwise, a {@link azure.build.core.ValidationException} will be thrown. + * + * Once in the validated state, the setX methods may not be called, but the other methods can be called normally. + */ +public class LazyConfiguration implements Configuration { + public class ValidationException extends Exception{ + public ValidationException(String string) { + super(string); + } + + private static final long serialVersionUID = 4547650327498908947L; + } + + + private EclipseTarget eclipseTarget = null; + private TranslationCatalogue translationCatalogue = null; + + private File workingDirectory = new File("."); + private File report = null; + private File eclipseRoot; + private File translationsRoot; + + private boolean validated = false; + private boolean includePseudoTranslations = false; + private boolean includeXmlReport = false; + private boolean longReport = false; + private String localeExtension; + + private final List<Filter> filters = new LinkedList<Filter>(); + private final Set<LocaleProxy> locales = new HashSet<LocaleProxy>(); + private final Set<LocaleGroup> localeGroups = new HashSet<LocaleGroup>(); + private final Set<String> excludeList = new HashSet<String>(); + + public EclipseTarget eclipseInstall() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + try { + if(eclipseTarget == null){ + eclipseTarget = new EclipseTarget(eclipseRoot, new HashSet<String>()); + eclipseTarget.populatePlugins(); + } + } catch (Exception e) {} + return eclipseTarget; + } + + public void setArchiveRoot(File root){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + eclipseRoot = root; + } + + public Range compatibilityRange() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Not implemented yet!"); + } + + public void setCompatibilityRange(String range){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + // TODO + throw new UnsupportedOperationException("Not implemented yet!"); + } + + public List<Filter> filters() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return filters ; + } + + public void addFilters(List<Filter> filters){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + this.filters.addAll(filters); + } + + public boolean includePseudoTranslations() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return includePseudoTranslations; + } + + public void setIncludePseudoTranslations(boolean include){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + this.includePseudoTranslations = include; + } + + public boolean includeResource(PluginProxy plugin, ResourceProxy resource) { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + for(Filter filter : filters){ + if(filter.matches(plugin, resource)){ + return filter.isInclusive(); + } + } + + return true; + } + + public Set<LocaleProxy> locales() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return locales; + } + + public void addLocales(Set<LocaleProxy> locales){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + this.locales.addAll(locales); + } + + public File reportLocation() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + if(report == null){ + return new File(workingDirectory, "coverage.xml"); + } + + return report; + } + + public void setReportLocation(File file){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + report = file; + } + + public Date timestamp() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + return new Date(); + } + + public TranslationCatalogue translations() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + try { + if(translationCatalogue == null){ + if(localeGroups.isEmpty()){ + translationCatalogue = new TranslationCatalogue(translationsRoot, locales); + } else { + locales.clear(); + translationCatalogue = new TranslationCatalogue(translationsRoot, localeGroups); + locales.addAll(translationCatalogue.getAllLocales()); + } + } + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + return translationCatalogue; + } + + public void setTranslationsRoot(File translations){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + this.translationsRoot = translations; + } + + public File workingDirectory() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return workingDirectory; + } + + public void setWorkingDirectory(File file){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + workingDirectory = file; + } + + public void validate() throws ValidationException{ + if(eclipseRoot == null || !eclipseRoot.exists()){ + throw new ValidationException("Eclipse root does not exist."); + } + + if(translationsRoot == null || !translationsRoot.exists()){ + throw new ValidationException("Translation root does not exist."); + } + + if(workingDirectory == null || !workingDirectory.exists()){ + throw new ValidationException("Working directory does not exist."); + } + + validated = true; + } + + public boolean isValidated() { + return validated; + } + + public Set<LocaleGroup> localeGroups() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return localeGroups; + } + + public void addLocaleGroups(Set<LocaleGroup> localeGroups){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + this.localeGroups.addAll(localeGroups); + } + + public Set<String> excludeList() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return excludeList; + } + + public void addExclude(String exclude){ + this.excludeList.add(exclude); + } + + public void addFilter(Filter filter) { + filters.add(filter); + } + + public void notifyProgress(String fragmentName) { + // TODO Auto-generated method stub + } + + public boolean includeXmlReport() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return includeXmlReport; + } + + public void setIncludeXmlReport(boolean include){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + includeXmlReport = include; + } + + public boolean longReport() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return longReport; + } + + public void setLongReport(boolean longReport){ + if(isValidated()){ + throw new IllegalStateException("setX methods cannot be called once the instance has been validated."); + } + + this.longReport = longReport; + } + + public String localeExtension() { + if(!isValidated()){ + throw new IllegalStateException("LazyConfiguration must be validated before this method may be called"); + } + + return localeExtension; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleGroup.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleGroup.java new file mode 100644 index 0000000..c37a192 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleGroup.java
@@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +public enum LocaleGroup { + + GROUP_ALL (Messages.getString("Groups_all"), Messages.getString("Groups_all_full"), 0), //$NON-NLS-1$ + GROUP_1 (Messages.getString("Groups_group1"), Messages.getString("Groups_group1_full"), 1), //$NON-NLS-1$ + GROUP_2 (Messages.getString("Groups_group2"), Messages.getString("Groups_group2_full"), 2), //$NON-NLS-1$ + GROUP_2A (Messages.getString("Groups_group2a"), Messages.getString("Groups_group2a_full"), 3), //$NON-NLS-1$ + GROUP_BIDI (Messages.getString("Groups_groupBidi"), Messages.getString("Groups_groupBidi_full"), 4); //$NON-NLS-1$ + + private String name; + private String fullName; + private int number; + + private LocaleGroup(String name, String fullName, int number) { + this.name = name; + this.fullName = fullName; + this.number = number; + } + + public String getName() { + return name; + } + + public String getFullName() { + return fullName; + } + + public int getNumber() { + return number; + } + + public static LocaleGroup get(String name) { + for (LocaleGroup group : LocaleGroup.values()) { + if (group.name.compareToIgnoreCase(name) == 0) { + return group; + } + } + return LocaleGroup.GROUP_ALL; + } + + public static LocaleGroup getByFullName(String fullName) { + for (LocaleGroup group : LocaleGroup.values()) { + if (group.fullName.compareToIgnoreCase(fullName) == 0) { + return group; + } + } + return LocaleGroup.GROUP_ALL; + } + + public static LocaleGroup get(Integer number) { + for (LocaleGroup group : LocaleGroup.values()) { + if (group.number == number) { + return group; + } + } + return LocaleGroup.GROUP_ALL; + } + + public static boolean isValidGroupName(String name) { + for (LocaleGroup group : LocaleGroup.values()) { + if (group.name.compareToIgnoreCase(name) == 0) { + return true; + } + } + return false; + } + + public static boolean isValidGroupFullName(String fullName) { + for (LocaleGroup group : LocaleGroup.values()) { + if (group.fullName.compareToIgnoreCase(fullName) == 0) { + return true; + } + } + return false; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleProxy.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleProxy.java new file mode 100644 index 0000000..b261bec --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/LocaleProxy.java
@@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; + +public class LocaleProxy { + public static final Set<LocaleProxy> ALL = new HashSet<LocaleProxy>(); + public static final Comparator<LocaleProxy> NAME_COMPARATOR = new Comparator<LocaleProxy>(){ + public int compare(LocaleProxy o1, LocaleProxy o2) { + return o1.name.compareTo(o2.name); + } + }; + private String name; + + public LocaleProxy(String name) { + this.name = name; + } + + public String getName(){ + return name; + } + + public boolean equals(Object object) { + LocaleProxy locale = (LocaleProxy)object; + return locale.getName().equals(this.name); + } + + public int hashCode() { + return this.name.hashCode(); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Main.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Main.java new file mode 100644 index 0000000..de0f8bd --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Main.java
@@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import org.eclipse.babel.build.core.Options.MissingArgument; +import org.eclipse.babel.build.core.Options.UnsetMandatoryOption; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.exceptions.FailedDeletionException; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.languagepack.LanguagePack; + + +public class Main { + + public static void main (String[] args) { + try { + CommandLineConfiguration config = new CommandLineConfiguration(args); + + long startLanguagePackGeneration = System.currentTimeMillis(); + LanguagePack languagePack = new LanguagePack(config); + System.out.println(); + System.out.println(Messages.getString("Messages_generating_language_pack")); //$NON-NLS-1$ + + LanguagePackCoverageReport coverage; + coverage = languagePack.generate(); + Configuration.helper.printLanguagePackResult(config, coverage); + + config.times.languagePackGeneration = System.currentTimeMillis() - startLanguagePackGeneration; + + System.out.println("\nEclipse Target parsed in: " + config.times.eclipseInstallPopulation); //$NON-NLS-1$ + System.out.println("Language Pack generated in: " + config.times.languagePackGeneration); //$NON-NLS-1$ + + } catch (MissingArgument e) { + System.out.println(Messages.getString("Error_missing_argument") + e.getMessage()); //$NON-NLS-1$ + System.exit(-1); + } catch (UnsetMandatoryOption e) { + System.out.println(Messages.getString("Error_unset_mandatory_exception") + e.getMessage()); //$NON-NLS-1$ + System.exit(-1); + } catch (InvalidFilenameException i) { + System.out.println( Messages.getString("Error_invalid_working_directory_name") ); //$NON-NLS-1$ + System.exit(0); + } catch (FailedDeletionException f) { + System.out.println( Messages.getString("Error_deleting_working_directory") ); //$NON-NLS-1$ + System.exit(0); + } catch (Exception e) { + System.out.println( Messages.getString("Error_language_pack") + ": " + e.getMessage()); //$NON-NLS-1$ $NON-NLS-2$ + System.exit(0); + } + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Messages.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Messages.java new file mode 100644 index 0000000..cfda238 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Messages.java
@@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages { + private static final String BUNDLE_NAME = "org.eclipse.babel.build.core.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Options.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Options.java new file mode 100644 index 0000000..90e6454 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Options.java
@@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class Options { + public static class UnknownOption extends RuntimeException{ + private static final long serialVersionUID = 5843082921291728978L; + + public UnknownOption(String name) { + super(name); + } + } + + public static class UnsetMandatoryOption extends RuntimeException{ + private static final long serialVersionUID = 4112908586458361303L; + + public UnsetMandatoryOption(String name){ + super(name); + } + } + + public static class MissingArgument extends RuntimeException{ + private static final long serialVersionUID = 4845067566513625318L; + + public MissingArgument(String message){ + super(message); + } + } + + private class Option { + private final String name; + private String value = null; + private final boolean needsArg; + private final boolean mandatory; + + public Option(String specifier){ + mandatory = specifier.endsWith("!"); + needsArg = specifier.endsWith("=") || specifier.endsWith("=!"); + name = specifier.substring(0, specifier.length() - (needsArg ? 1 : 0) - (mandatory ? 1 : 0)); + } + } + + private final Map<String, Option> values = new HashMap<String, Option>(); + private final List<String> params = new LinkedList<String>(); + + public Options(String... opts) { + for(String opt : opts){ + Option o = new Option(opt); + values.put(o.name, o); + } + } + + public Options parse(String... args) { + for(int i = 0; i < args.length; i++){ + Option opt = values.get(args[i]); + + if(opt == null){ + params.add(args[i]); + } else { + if(opt.needsArg){ + if(i < args.length - 1){ + opt.value = args[i + 1]; + } else { + throw new MissingArgument(args[i]); + } + i++; + } else { + opt.value = ""; + } + } + } + + for(String name : values.keySet()){ + Option opt = values.get(name); + if(opt.mandatory && opt.value == null){ + throw new UnsetMandatoryOption(name); + } + } + + return this; + } + + public boolean isSet(String name){ + try{ + return values.get(name).value != null; + } catch (NullPointerException ex){ + throw new UnknownOption(name); + } + } + + public List<String> getParams() { + return params; + } + + public String get(String name) { + return get(name, null); + } + + public String get(String name, String default_) { + try{ + String value = values.get(name).value; + if(value == null){ + return default_; + } + return value; + } catch (NullPointerException ex){ + throw new UnknownOption(name); + } + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/PluginProxy.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/PluginProxy.java new file mode 100644 index 0000000..3f17b4e --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/PluginProxy.java
@@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.io.File; +import java.util.List; + +public class PluginProxy { + private String name; + private File pluginLocation; + private String version; + private boolean isJar; + private boolean isFeature; + private List<ResourceProxy> resources; + + public PluginProxy(File pluginLocation, List<ResourceProxy> resources, boolean isJar, boolean isFeature){ + this.pluginLocation = pluginLocation; + if(pluginLocation.getName().matches(Messages.getString("Patterns_plugin_name"))) { //$NON-NLS-1$ + this.name = pluginLocation.getName().substring(0, pluginLocation.getName().indexOf(Messages.getString("Characters_underscore"))); //$NON-NLS-1$ + this.version = pluginLocation.getName().substring(pluginLocation.getName().indexOf(Messages.getString("Characters_underscore")) + 1); //$NON-NLS-1$ + if(isJar) { + this.version = version.replaceAll(Messages.getString("Extensions_jar"), ""); //$NON-NLS-1$ + } + } + else { + this.name = pluginLocation.getName(); + this.version = ""; //$NON-NLS-1$ + } + this.resources = resources; + this.isJar = isJar; + this.isFeature = isFeature; + } + + public String getName(){ + //TODO: stub + return this.name; + } + + public String getVersion(){ + //TODO: stub + return this.version; + } + + public List<ResourceProxy> getResources() { + return resources; + } + + public boolean isJar() { + return isJar; + } + + public File getPluginLocation() { + return pluginLocation; + } + + public boolean isFeature() { + return isFeature; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Range.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Range.java new file mode 100644 index 0000000..1ed7b83 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/Range.java
@@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +public class Range { + public boolean contains(String version){ + //TODO: stub + return false; + } + + public String toString(){ + //TODO: stub + return ""; + } + + + public static Range parse(String range){ + //TODO: stub + return null; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/ResourceProxy.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/ResourceProxy.java new file mode 100644 index 0000000..6481294 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/ResourceProxy.java
@@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core; + +import java.io.File; + +public class ResourceProxy { + private File fileResource; /** From translation catalogue */ + private String relativePath; /** From eclipse target */ + private String canonicalPath; + + public ResourceProxy(File fileResource) { + this.fileResource = fileResource; + } + + public ResourceProxy(String relativePath) { + this.relativePath = relativePath; + this.relativePath = this.relativePath.replace('/', File.separatorChar); + this.canonicalPath = relativePath.replace(File.separatorChar, '/'); + } + + public ResourceProxy(File fileResource, String relativePath) { + this.fileResource = fileResource; + this.relativePath = relativePath.replace('/', File.separatorChar); + this.canonicalPath = relativePath.replace(File.separatorChar, '/'); + } + + public File getFileResource() { + return fileResource; + } + + public String getRelativePath() { + return relativePath; + } + + public String getCanonicalPath() { + return canonicalPath; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/CoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/CoverageReport.java new file mode 100644 index 0000000..36271f7 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/CoverageReport.java
@@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.coverage; + +import java.io.InputStream; +import java.io.OutputStream; + +public interface CoverageReport { + public static class helper{ + public static void serialize(OutputStream out){ + // TODO: stub + } + + public static CoverageReport parse(InputStream in){ + // TODO: stub + return null; + } + } + /** + public List<LocaleProxy> locales(); + public List<PluginProxy> plugins(); + public Date timestamp(); + public EclipseArchive archive(); + public TranslationArchive translations(); + public LanguagePack catalogue(); + */ +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/LanguagePackCoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/LanguagePackCoverageReport.java new file mode 100644 index 0000000..c44586b --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/LanguagePackCoverageReport.java
@@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.coverage; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.babel.build.core.LocaleProxy; + + +public class LanguagePackCoverageReport implements CoverageReport { + private List<PluginCoverageInformation> pluginCoverageReports = new ArrayList<PluginCoverageInformation>(); + private Map<LocaleProxy, Integer> matchesPerLocale = new HashMap<LocaleProxy, Integer>(); + private List<LocaleProxy> locales = new ArrayList<LocaleProxy>(); + + public LanguagePackCoverageReport(Collection<LocaleProxy> locales) { + super(); + this.locales.addAll(locales); + initializeMap(); + } + + /** Adds coverage information about a single plug-in to overall coverage report. */ + public void addPluginCoverageToReport(PluginCoverageInformation pluginCoverageInformation) { + this.pluginCoverageReports.add(pluginCoverageInformation); + + for (LocaleProxy locale : pluginCoverageInformation.getPluginMatchingPerLocale().keySet()) { + if (pluginCoverageInformation.getPluginMatchingPerLocale().get(locale)) { + this.matchesPerLocale.put(locale, this.matchesPerLocale.get(locale) + 1); + } + } + } + + /** Returns coverage information about each individual plug-in in the Eclipse install. */ + public List<PluginCoverageInformation> getPluginCoverageReports() { + return pluginCoverageReports; + } + + /** Returns number of matched plug-ins for each locale. */ + public Map<LocaleProxy, Integer> getMatchesPerLocale() { + return matchesPerLocale; + } + + private void initializeMap() { + for (LocaleProxy locale : locales) { + this.matchesPerLocale.put(locale, 0); + } + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/PluginCoverageInformation.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/PluginCoverageInformation.java new file mode 100644 index 0000000..d7d631f --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/PluginCoverageInformation.java
@@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.coverage; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; + + +public class PluginCoverageInformation { + public static final Comparator<PluginCoverageInformation> NAME_COMPARATOR = new Comparator<PluginCoverageInformation>(){ + public int compare(PluginCoverageInformation o1, PluginCoverageInformation o2) { + String name1 = o1.getEclipseArchivePlugin().getName(); + String name2 = o2.getEclipseArchivePlugin().getName(); + return name1.compareTo(name2); + } + }; + + private final PluginProxy eclipseArchivePlugin; + private Map<String, ResourceCoverageInformation> resourceCoverage = + new HashMap<String, ResourceCoverageInformation>(); + private Map<LocaleProxy, Boolean> pluginMatchingPerLocale = new HashMap<LocaleProxy, Boolean>(); + + public PluginCoverageInformation(PluginProxy eclipseArchivePlugin) { + super(); + this.eclipseArchivePlugin = eclipseArchivePlugin; + } + + /** Returns a PluginProxy which represents the plug-in in question. */ + public PluginProxy getEclipseArchivePlugin() { + return eclipseArchivePlugin; + } + + /** Returns a map which, for each locale, indicates whether or not plug-in was matched. */ + public Map<LocaleProxy, Boolean> getPluginMatchingPerLocale() { + return this.pluginMatchingPerLocale; + } + + /** Given a specific locale, indicates whether or not plug-in was matched. */ + public Boolean getPluginMatchingForLocale(String locale) { + for (LocaleProxy localeFromList: pluginMatchingPerLocale.keySet()) { + if (localeFromList.getName().compareToIgnoreCase(locale) == 0) { + return this.pluginMatchingPerLocale.get(localeFromList); + } + } + + return false; + } + + /** Records whether or not the plug-in in question was matched to a specific locale. */ + public void setPluginMatchingForLocale(LocaleProxy locale, Boolean matched) { + this.pluginMatchingPerLocale.put(locale, matched); + } + + /** Records whether or not a resource belonging to the plug-in in question was matched to a specific locale. */ + public void setResourceCoverageForLocale(LocaleProxy locale, ResourceProxy resource, Boolean matched) { + if (this.resourceCoverage.containsKey(resource.getRelativePath())) { + ResourceCoverageInformation info = this.resourceCoverage.get(resource.getRelativePath()); + info.setMatchingForLocale(locale, matched); + } else { + ResourceCoverageInformation info = new ResourceCoverageInformation(resource); + info.setMatchingForLocale(locale, matched); + this.resourceCoverage.put(resource.getRelativePath(), info); + + } + } + + /** Records whether or not a resource belonging to the plug-in in question was matched to a specific locale. */ + public void setResourceCoverageForLocale(LocaleProxy locale, ResourceProxy resource, Boolean matched, int propertiesCoverage) { + if (this.resourceCoverage.containsKey(resource.getRelativePath())) { + ResourceCoverageInformation info = this.resourceCoverage.get(resource.getRelativePath()); + info.setMatchingForLocale(locale, matched); + info.setMatchedPercentageForLocale(locale, propertiesCoverage); + } else { + ResourceCoverageInformation info = new ResourceCoverageInformation(resource); + info.setMatchingForLocale(locale, matched); + info.setMatchedPercentageForLocale(locale, propertiesCoverage); + this.resourceCoverage.put(resource.getRelativePath(), info); + + } + } + + /** Returns coverage information about resource belonging to the plug-in in question */ + public Map<String, ResourceCoverageInformation> getResourceCoverage() { + return resourceCoverage; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/ResourceCoverageInformation.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/ResourceCoverageInformation.java new file mode 100644 index 0000000..cff9c47 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/coverage/ResourceCoverageInformation.java
@@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.coverage; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.ResourceProxy; + + +public class ResourceCoverageInformation { + private final ResourceProxy resource; + private Map<LocaleProxy, Boolean> matchingByLocale = new HashMap<LocaleProxy, Boolean>(); + private Map<LocaleProxy, Integer> matchedPercentageForLocale = new HashMap<LocaleProxy, Integer>(); + + public ResourceCoverageInformation(ResourceProxy resource){ + this.resource = resource; + } + + public ResourceProxy getResource() { + return resource; + } + + public void setMatchingForLocale(LocaleProxy locale, Boolean matched) { + this.matchingByLocale.put(locale, matched); + } + + public Boolean getMatchingForLocale(LocaleProxy locale) { + return this.matchingByLocale.get(locale); + } + + public Boolean getMatchingForLocale(String locale) { + for (LocaleProxy localeFromList: matchingByLocale.keySet()) { + if (localeFromList.getName().compareToIgnoreCase(locale) == 0) { + return this.matchingByLocale.get(localeFromList); + } + } + + return false; + } + + public void setMatchedPercentageForLocale(LocaleProxy locale, Integer value) { + this.matchedPercentageForLocale.put(locale, value); + } + + public Integer getMatchedPercentageForLocale(LocaleProxy locale) { + return this.matchedPercentageForLocale.get(locale); + } + + public Set<LocaleProxy> getRecordedLocales() { + return this.matchingByLocale.keySet(); + } + + public Map<LocaleProxy, Boolean> getLocaleMatchMap(){ + return Collections.unmodifiableMap(matchingByLocale); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseArchiveInstallParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseArchiveInstallParser.java new file mode 100644 index 0000000..5866fd6 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseArchiveInstallParser.java
@@ -0,0 +1,359 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; + + +public class EclipseArchiveInstallParser implements EclipseParser { + + private ZipFile eclipseArchive; + private File archiveLocation; + + //The lists of plug-ins/features will be stored in maps for faster lookup + private Map<String, PluginProxy> plugins = new HashMap<String, PluginProxy>(); + private Map<String, PluginProxy> features = new HashMap<String, PluginProxy>(); + + private Set<String> excludeList; + + public EclipseArchiveInstallParser(ZipFile eclipseArchive, File archiveLocation) throws InvalidLocationException { + this.eclipseArchive = eclipseArchive; + this.archiveLocation = archiveLocation; + + validateTarget(); + useDefaultList(); + } + + public EclipseArchiveInstallParser(ZipFile eclipseArchive, File archiveLocation, Set<String> excludeList) throws InvalidLocationException { + this.eclipseArchive = eclipseArchive; + this.archiveLocation = archiveLocation; + + validateTarget(); + + useDefaultList(); + this.excludeList.addAll(excludeList); + } + + @SuppressWarnings("unchecked") + private void validateTarget() throws InvalidLocationException { + boolean foundPluginsPath = false; + boolean foundFeaturesPath = false; + for (Enumeration entries = eclipseArchive.entries(); entries.hasMoreElements();) { + ZipEntry entry = (ZipEntry)entries.nextElement(); + + if (entry.getName().contains(PLUGINS_PATH)) { + foundPluginsPath = true; + } else if (entry.getName().contains(FEATURES_PATH)) { + foundFeaturesPath = true; + } + } + if ( (!foundFeaturesPath) || (!foundPluginsPath) ) { + throw new InvalidLocationException(); + } + } + + private class ExtractionParameters { + List<ResourceProxy> resourcesOfLastPlugin = new LinkedList<ResourceProxy>(); + ZipEntry entry; + ZipEntry lastPluginOrFeatureEntry = null; + String name; + String tempPluginOrFeaturePath; + String lastPluginOrFeature = PLUGIN_MASK; + String lastPluginOrFeaturePath = ""; //$NON-NLS-1$ + + public List<ResourceProxy> getResourcesOfLastPlugin() { + return resourcesOfLastPlugin; + } + public ZipEntry getEntry() { + return entry; + } + public ZipEntry getLastPluginOrFeatureEntry() { + return lastPluginOrFeatureEntry; + } + public String getName() { + return name; + } + public String getTempPluginOrFeaturePath() { + return tempPluginOrFeaturePath; + } + public String getLastPluginOrFeature() { + return lastPluginOrFeature; + } + public String getLastPluginOrFeaturePath() { + return lastPluginOrFeaturePath; + } + public void setResourcesOfLastPlugin(List<ResourceProxy> resourcesOfLastPlugin) { + this.resourcesOfLastPlugin = resourcesOfLastPlugin; + } + public void setEntry(ZipEntry entry) { + this.entry = entry; + } + public void setLastPluginOrFeatureEntry(ZipEntry lastPluginOrFeatureEntry) { + this.lastPluginOrFeatureEntry = lastPluginOrFeatureEntry; + } + public void setName(String name) { + this.name = name; + } + public void setTempPluginOrFeaturePath(String tempPluginOrFeaturePath) { + this.tempPluginOrFeaturePath = tempPluginOrFeaturePath; + } + public void setLastPluginOrFeature(String lastPluginOrFeature) { + this.lastPluginOrFeature = lastPluginOrFeature; + } + public void setLastPluginOrFeaturePath(String lastPluginOrFeaturePath) { + this.lastPluginOrFeaturePath = lastPluginOrFeaturePath; + } + } + + @SuppressWarnings("unchecked") + public void parse() throws Exception { + ExtractionParameters parameters = new ExtractionParameters(); + + boolean ignorePlugin = false; + + for (Enumeration entries = eclipseArchive.entries(); entries.hasMoreElements();) { + parameters.setEntry( (ZipEntry)entries.nextElement() ); + parameters.setName( parameters.getEntry().getName() ); + + if (parameters.getName().equalsIgnoreCase(PLUGINS_PATH) + || parameters.getName().equalsIgnoreCase(FEATURES_PATH)) { + //Ignore case + } + /** Potential Non-JARed Plug-in or Feature */ + else if (parameters.getName().endsWith(DIRECTORY_SUFFIX) && (parameters.getName().contains(PLUGINS_PATH) + || parameters.getName().contains(FEATURES_PATH))) { + + if (parameters.getName().contains(PLUGINS_PATH)) { + parameters.setTempPluginOrFeaturePath(PLUGINS_PATH); + } + else { + parameters.setTempPluginOrFeaturePath(FEATURES_PATH); + } + parameters.setName( removePluginOrFeaturePath(parameters.getName(), 1) ); + + /** Non-JARed Plug-in */ + if (!parameters.getName().contains(DIRECTORY_SUFFIX)) { + boolean ignorePrevious = ignorePlugin; + if (!isValidPlugin(parameters.getName())) { + ignorePlugin = true; + } else { + ignorePlugin = false; + } + handleNonJarPluginOrFeature(parameters, ignorePrevious); + } + } + /** Plug-in JAR */ + else if ( parameters.getName().endsWith(JAR_EXTENSION) && + (!parameters.getName().contains(parameters.getLastPluginOrFeature())) && + (isValidPlugin(parameters.getName())) ) { + handleJarPlugin(parameters); + } + else if ( parameters.getName().endsWith(JAR_EXTENSION) && + (parameters.getName().contains(parameters.getLastPluginOrFeature())) && + (isValidResource(parameters.getName())) ) { + handleJarResource(parameters); + } + /** Translatable Resource for Non-JARed Plug-in or Feature*/ + else if ( isTranslatableResource(parameters.getName(), parameters) && (!ignorePlugin) ) { + handleTranslatableResource(parameters); + } + } + + handleLastPluginOrFeatureEntry(parameters); + } + + private void handleJarResource(ExtractionParameters parameters) throws Exception { + List<ResourceProxy> jarResources = new ArrayList<ResourceProxy>(); + + String frontRelativePath = ""; + + if (parameters.getName().contains(DIRECTORY_SUFFIX)) { + frontRelativePath = parameters.getName().substring(parameters.getName().lastIndexOf(DIRECTORY_SUFFIX)+1); + } + frontRelativePath = frontRelativePath.replaceAll(JAR_EXTENSION, ""); + frontRelativePath += "_jar"; + + InputStream input = eclipseArchive.getInputStream(parameters.getEntry()); + ZipInputStream zipInput = new ZipInputStream(input); + + ZipEntry zipEntry = zipInput.getNextEntry(); + while(zipEntry != null) { + String resourceEntryName = zipEntry.getName(); + + if ( isValidResource(resourceEntryName) && (!resourceEntryName.contains(META_INF_DIR_NAME))) { + String relativePath = frontRelativePath + File.separator + resourceEntryName; + relativePath = relativePath.replace("\\", File.separator); + relativePath = relativePath.replace("/", File.separator); + jarResources.add(new ResourceProxy( + new File(archiveLocation.getAbsolutePath() + SLASH + + parameters.getName() + SLASH + resourceEntryName), relativePath)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + zipEntry = zipInput.getNextEntry(); + } + + parameters.getResourcesOfLastPlugin().addAll(jarResources); + } + + private void handleNonJarPluginOrFeature(ExtractionParameters parameters, boolean ignorePrevious) { + //If it's not the first plug-in/feature that we come across + if (!parameters.getLastPluginOrFeature().equals(PLUGIN_MASK) && (!ignorePrevious)) { + PluginProxy newPlugin; + + String lastEntryName = parameters.getLastPluginOrFeatureEntry().getName(); + if (!lastEntryName.startsWith(File.separator)) { + lastEntryName = File.separator + lastEntryName; + } + + if (parameters.getLastPluginOrFeaturePath().equals(PLUGINS_PATH)) { + newPlugin = new PluginProxy(new File(archiveLocation.getAbsolutePath(), + lastEntryName), + parameters.getResourcesOfLastPlugin(), false, false); + plugins.put(newPlugin.getName(), newPlugin); + } + else { + newPlugin = new PluginProxy(new File(archiveLocation.getAbsolutePath(), + lastEntryName), + parameters.getResourcesOfLastPlugin(), false, true); + features.put(newPlugin.getName(), newPlugin); + } + parameters.setResourcesOfLastPlugin( new LinkedList<ResourceProxy>() ); + } + + parameters.setLastPluginOrFeature( parameters.getName() ); + parameters.setLastPluginOrFeatureEntry( parameters.getEntry() ); + parameters.setLastPluginOrFeaturePath( parameters.getTempPluginOrFeaturePath() ); + } + + private void handleJarPlugin(ExtractionParameters parameters) throws Exception { + List<ResourceProxy> jarResources = new LinkedList<ResourceProxy>(); + parameters.setName( removePluginOrFeaturePath(parameters.getName(), 0) ); + parameters.setName( parameters.getName().replaceAll(JAR_EXTENSION, "") ); //$NON-NLS-1$ + + InputStream input = eclipseArchive.getInputStream(parameters.getEntry()); + ZipInputStream zipInput = new ZipInputStream(input); + + ZipEntry zipEntry = zipInput.getNextEntry(); + while(zipEntry != null) { + String resourceEntryName = zipEntry.getName(); + + if ( isValidResource(resourceEntryName) ) { + jarResources.add(new ResourceProxy( + new File(archiveLocation.getAbsolutePath() + File.separator + + parameters.getEntry().getName() + File.separator + resourceEntryName), resourceEntryName)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + zipEntry = zipInput.getNextEntry(); + } + + PluginProxy newPlugin = new PluginProxy(new File(archiveLocation.getAbsolutePath(), + parameters.getEntry().getName()), jarResources, true, false); + plugins.put(newPlugin.getName(), newPlugin); + } + + private boolean isTranslatableResource(String resourceName, ExtractionParameters parameters) { + return isValidResource(resourceName) + && (resourceName.startsWith(PLUGINS_PATH) || resourceName.startsWith(FEATURES_PATH)); + } + + private boolean isValidPlugin(String name) { + name = removePluginOrFeaturePath(name, 0); + for (String exclude : this.excludeList) { + if (name.matches(exclude)) { + return false; + } + } + return true; + } + + private boolean isValidResource(String name) { + if (name.contains(DIRECTORY_SUFFIX)) { + name = name.substring(name.lastIndexOf(DIRECTORY_SUFFIX)+1); + + if (name.length() == 0) { + return false; + } + } + for (String exclude : this.excludeList) { + if (name.matches(exclude)) { + return false; + } + } + return true; + } + + private void handleTranslatableResource(ExtractionParameters parameters) { + String resource = removePluginOrFeaturePath(parameters.getName(), 0); + resource = resource.replaceAll(parameters.getLastPluginOrFeature(), ""); //$NON-NLS-1$ + parameters.getResourcesOfLastPlugin().add(new ResourceProxy(new File(eclipseArchive.getName() + + Messages.getString("Characters_entry_separator") + parameters.getName()), resource.substring(1))); //$NON-NLS-1$ + } + + private void handleLastPluginOrFeatureEntry(ExtractionParameters parameters) { + if (parameters.getLastPluginOrFeatureEntry() != null) { + //Add last feature or plug-in + PluginProxy newPlugin; + if (parameters.getLastPluginOrFeaturePath().equals(PLUGINS_PATH)) { + newPlugin = new PluginProxy(new File(archiveLocation.getAbsolutePath(), + parameters.getLastPluginOrFeatureEntry().getName()), parameters.getResourcesOfLastPlugin(), false, false); + plugins.put(newPlugin.getName(), newPlugin); + } + else { + newPlugin = new PluginProxy(new File(archiveLocation.getAbsolutePath(), + parameters.getLastPluginOrFeatureEntry().getName()), parameters.getResourcesOfLastPlugin(), false, true); + features.put(newPlugin.getName(), newPlugin); + } + } + parameters.setResourcesOfLastPlugin( new LinkedList<ResourceProxy>() ); + } + + private String removePluginOrFeaturePath(String name, int charactersToRemoveAtEnd) { + name = name.replaceAll(PLUGINS_PATH, ""); //$NON-NLS-1$ + name = name.replaceAll(FEATURES_PATH, ""); //$NON-NLS-1$ + name = name.substring(0, name.length() - charactersToRemoveAtEnd); + return name; + } + + private void useDefaultList() { + this.excludeList = new HashSet<String>(); + for ( String exclude : DEFAULT_EXCLUDE_LIST) { + this.excludeList.add(exclude); + } + + this.excludeList.add(PATTERN_DIR); + + } + + public Map<String, PluginProxy> getPlugins() { + return plugins; + } + + public Map<String, PluginProxy> getFeatures() { + return features; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseInstallParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseInstallParser.java new file mode 100644 index 0000000..6574c0d --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseInstallParser.java
@@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarInputStream; +import java.util.zip.ZipEntry; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; + + +public class EclipseInstallParser implements EclipseParser { + + private final static String PLUGINS_PATH = Messages.getString("Paths_plugins_directory"); //$NON-NLS-1$ + private final static String FEATURES_PATH = Messages.getString("Paths_features_directory"); //$NON-NLS-1$ + + private Set<String> excludeList = new HashSet<String>(); + + private File eclipseInstallLocation; + //The lists of plug-ins/features will be stored in maps for faster lookup + private Map<String, PluginProxy> plugins = new HashMap<String, PluginProxy>(); + private Map<String, PluginProxy> features = new HashMap<String, PluginProxy>(); + + public EclipseInstallParser(File eclipseInstallLocation) throws InvalidLocationException { + this.eclipseInstallLocation = eclipseInstallLocation; + + validateTarget(); + useDefaultList(); + } + + public EclipseInstallParser(File eclipseInstallLocation, Set<String> excludeList) throws InvalidLocationException { + this.eclipseInstallLocation = eclipseInstallLocation; + + validateTarget(); + + useDefaultList(); + this.excludeList.addAll(excludeList); + } + + private void validateTarget() throws InvalidLocationException { + String pluginPath = Messages.getString("Paths_plugins_directory"); //$NON-NLS-1$ + pluginPath = pluginPath.replace(Messages.getString("Characters_entry_separator"), File.separator); //$NON-NLS-1$ + String featurePath = Messages.getString("Paths_features_directory"); //$NON-NLS-1$ + featurePath = featurePath.replace(Messages.getString("Characters_entry_separator"), File.separator); //$NON-NLS-1$ + + File pluginDir = new File(this.eclipseInstallLocation.getAbsolutePath(), pluginPath); + File featureDir = new File(this.eclipseInstallLocation.getAbsolutePath(), featurePath); + + if ( (!pluginDir.exists()) || (!featureDir.exists()) ) { + throw new InvalidLocationException(); + } + } + + public void parse() throws Exception { + + PluginProxy newPlugin; + File pluginsRoot = new File(this.eclipseInstallLocation.getAbsolutePath() + File.separatorChar + PLUGINS_PATH); + + for (File plugin: pluginsRoot.listFiles()) { + List<ResourceProxy> pluginResources; + if (isValidPlugin(plugin.getName())) { + if(plugin.isDirectory()) { + pluginResources = extractResources(plugin, plugin.getName()); + newPlugin = new PluginProxy(plugin, pluginResources, false, false); + plugins.put(newPlugin.getName(), newPlugin); + } else { + //Handle JAR Plug-in + pluginResources = extractResourcesFromJar(plugin); + newPlugin = new PluginProxy(plugin, pluginResources, true, false); + plugins.put(newPlugin.getName(), newPlugin); + } + } + } + + PluginProxy newFeature; + File featuresRoot = new File(this.eclipseInstallLocation.getAbsolutePath() + File.separatorChar + FEATURES_PATH); + + for (File feature: featuresRoot.listFiles()) { + List<ResourceProxy> featureResources; + if (isValidPlugin(feature.getName())) { + if(feature.isDirectory()) { + featureResources = extractResources(feature, feature.getName()); + newFeature = new PluginProxy(feature, featureResources, false, true); + features.put(newFeature.getName(), newFeature); + } else { + //Handle JAR Feature + featureResources = extractResourcesFromJar(feature); + newFeature = new PluginProxy(feature, featureResources, true, true); + features.put(newFeature.getName(), newFeature); + } + } + } + } + + private List<ResourceProxy> extractResources(File file, String pluginName) throws Exception { + List<ResourceProxy> resources = new LinkedList<ResourceProxy>(); + for (File subFile: file.listFiles()) { + if (subFile.isDirectory()) { + resources.addAll(extractResources(subFile, pluginName)); + } + else { + if (isValidResource(subFile.getName())) { + if (subFile.getName().endsWith(JAR_EXTENSION)) { + resources.addAll(handleJarResource(subFile)); + } else { + String absolutePath = subFile.getAbsolutePath(); + String relativePath = absolutePath.substring(absolutePath.indexOf(pluginName)); + relativePath = relativePath.substring(pluginName.length() + 1); + resources.add(new ResourceProxy(subFile, relativePath)); + } + } + } + } + return resources; + } + + List<ResourceProxy> handleJarResource(File jarResource) throws Exception { + List<ResourceProxy> jarResources = new ArrayList<ResourceProxy>(); + + String frontRelativePath = jarResource.getName(); + + frontRelativePath = frontRelativePath.replaceAll(JAR_EXTENSION, ""); //$NON-NLS-1$ + frontRelativePath += JAR_RESOURCE_SUFFIX; + + InputStream input = new FileInputStream(jarResource); + JarInputStream zipInput = new JarInputStream(input); + + ZipEntry zipEntry = zipInput.getNextEntry(); + while(zipEntry != null) { + String resourceEntryName = zipEntry.getName(); + resourceEntryName = resourceEntryName.replace("\\", SLASH); //$NON-NLS-1$ + + if ( isValidResource(resourceEntryName) && (!resourceEntryName.contains(META_INF_DIR_NAME))) { + String relativePath = frontRelativePath + File.separator + resourceEntryName; + relativePath = relativePath.replace("\\", File.separator); //$NON-NLS-1$ + relativePath = relativePath.replace(SLASH, File.separator); + jarResources.add(new ResourceProxy(new File(jarResource.getAbsolutePath() + SLASH + + resourceEntryName), relativePath)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + zipEntry = zipInput.getNextEntry(); + } + + return jarResources; + } + + private List<ResourceProxy> extractResourcesFromJar(File file) { + List<ResourceProxy> jarResources = new LinkedList<ResourceProxy>(); + + try { + JarFile jarPluginOrFeature = new JarFile(file); + + Enumeration<JarEntry> jarEntries = jarPluginOrFeature.entries(); + + JarEntry jarEntry = jarEntries.nextElement(); + while (jarEntry != null) { + String resourceEntryName = jarEntry.getName(); + + if ( isValidResource(resourceEntryName) ) { + jarResources.add(new ResourceProxy( + new File(file.getAbsolutePath() + File.separator + + resourceEntryName), resourceEntryName)); + } + + if (jarEntries.hasMoreElements()) { + jarEntry = jarEntries.nextElement(); + } else { + jarEntry = null; + } + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + return jarResources; + } + + private boolean isValidPlugin(String name) { + for (String exclude : this.excludeList) { + if (name.matches(exclude)) { + return false; + } + } + return true; + } + + private boolean isValidResource(String name) { + if (name.contains(DIRECTORY_SUFFIX)) { + name = name.substring(name.lastIndexOf(DIRECTORY_SUFFIX)+1); + if (name.length() == 0) { + return false; + } + } + for (String exclude : this.excludeList) { + if (name.matches(exclude)) { + return false; + } + } + return true; + } + + private void useDefaultList() { + this.excludeList = new HashSet<String>(); + for ( String exclude : DEFAULT_EXCLUDE_LIST) { + this.excludeList.add(exclude); + } + } + + public Map<String, PluginProxy> getPlugins() { + return plugins; + } + + public Map<String, PluginProxy> getFeatures() { + return features; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseParser.java new file mode 100644 index 0000000..6d77077 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseParser.java
@@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.util.Map; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; + + +public interface EclipseParser { + + public final String JAR_EXTENSION = Messages.getString("Extensions_jar"); //$NON-NLS-1$ + public final String DIRECTORY_SUFFIX = Messages.getString("Suffixes_directory"); //$NON-NLS-1$ + public final String PLUGINS_PATH = Messages.getString("Paths_plugins_directory"); //$NON-NLS-1$ + public final String FEATURES_PATH = Messages.getString("Paths_features_directory"); //$NON-NLS-1$ + public final String SOURCE_SUFFIX = Messages.getString("Patterns_suffixes_source"); //$NON-NLS-1$ + public final String PLUGIN_MASK = Messages.getString("Masks_plugin"); //$NON-NLS-1$ + public final String JAVA_EXTENSION = Messages.getString("Extensions_java"); //$NON-NLS-1$ + public final String CLASS_EXTENSION = Messages.getString("Extensions_class"); //$NON-NLS-1$ + public final String PATTERN_DIR = Messages.getString("Patterns_non_jar_plugin"); //$NON-NLS-1$ + public final String META_INF_DIR_NAME = Messages.getString("Paths_meta_inf_directory"); //$NON-NLS-1$ + public final String JAR_RESOURCE_SUFFIX = Messages.getString("Suffixes_jar_resource_folder"); //$NON-NLS-1$ + public final String SLASH = Messages.getString("Characters_entry_separator"); //$NON-NLS-1$ + + public final String[] DEFAULT_EXCLUDE_LIST = {PATTERN_DIR, SOURCE_SUFFIX, JAVA_EXTENSION, CLASS_EXTENSION}; + + /** Parses an eclipse install and populates the plug-ins/features and their resources + in maps to be accessed at runtime. */ + public void parse() throws Exception; + + /** Returns the map containing the eclipse install plug-ins and their translatable + * resources. */ + public Map<String, PluginProxy> getPlugins(); + + /** Returns the map containing the eclipse install features and their translatable + * resources. */ + public Map<String, PluginProxy> getFeatures(); +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseTarget.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseTarget.java new file mode 100644 index 0000000..f66eb99 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/EclipseTarget.java
@@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipFile; + +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; +import org.eclipse.babel.build.core.exceptions.MissingLocationException; + + +public class EclipseTarget { + + private final File location; + private final boolean isArchive; + //The lists of plug-ins/features will be stored in maps for faster lookup + Map<String, PluginProxy> plugins = new HashMap<String, PluginProxy>(); + Map<String, PluginProxy> features = new HashMap<String, PluginProxy>(); + + private Set<String> excludeList; + + /** + * @param plugins - The list of plug-ins chosen via the wizard. + */ + public EclipseTarget(List<PluginProxy> plugins) { + for (PluginProxy plugin : plugins) { + this.plugins.put(plugin.getName(), plugin); + } + + this.isArchive = false; + this.location = new File( plugins.get(0).getPluginLocation().getParent() ); + } + + public EclipseTarget(File location, Set<String> excludeList) throws MissingLocationException, InvalidFilenameException { + this.location = location.getAbsoluteFile(); + + if (!this.location.exists()) { + throw new MissingLocationException(); + } + + this.excludeList = excludeList; + + if (location.isDirectory()) { + this.isArchive = false; + } else { + this.isArchive = true; + } + } + + /** + * Manipulates an EclipseParser to parse and populate the plug-ins and features + * in an Eclipse Install. + */ + public void populatePlugins() throws Exception, InvalidLocationException { + EclipseParser parser; + + if (!this.isArchive) { + parser = new EclipseInstallParser(location, excludeList); + } else { + ZipFile eclipseArchive = new ZipFile(location); + parser = new EclipseArchiveInstallParser(eclipseArchive, location, excludeList); + } + + parser.parse(); + + this.plugins = parser.getPlugins(); + this.features = parser.getFeatures(); + } + + public File getLocation(){ + return location; + } + + public Map<String, PluginProxy> getPlugins() { + return Collections.unmodifiableMap(plugins); + } + + public Map<String, PluginProxy> getFeatures() { + return Collections.unmodifiableMap(features); + } + + /** Returns whether or not EclipseInstall is an archive. */ + public boolean isArchive() { + return isArchive; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseArchiveMediator.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseArchiveMediator.java new file mode 100644 index 0000000..f20d776 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseArchiveMediator.java
@@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; + + +public class FragmentEclipseArchiveMediator implements + FragmentEclipseTargetMediator { + + private PluginProxy eclipseInstallPlugin; + private ZipFile eclipseArchive; + private File eclipseArchiveLocation; + + public FragmentEclipseArchiveMediator(PluginProxy eclipseInstallPlugin, File eclipseArchiveLocation) throws Exception { + this.eclipseInstallPlugin = eclipseInstallPlugin; + this.eclipseArchive = new ZipFile(eclipseArchiveLocation); + this.eclipseArchiveLocation = eclipseArchiveLocation; + } + + public Map<String, Set<Object>> extractEclipseTargetProperties() + throws ZipException, IOException, FileNotFoundException { + + Map<String, Set<Object>> propertiesMap = new HashMap<String, Set<Object>>(); + + // Determine the entry name of the JAR plug-in + InputStream jarPluginInputStream; + String jarPluginRelativePath = eclipseInstallPlugin.getPluginLocation().getAbsolutePath().replace(eclipseArchiveLocation.getAbsolutePath(), ""); + jarPluginRelativePath = jarPluginRelativePath.substring(1); + jarPluginRelativePath = jarPluginRelativePath.replace( + File.separator, Messages.getString("Characters_entry_separator")); //$NON-NLS-1$ + + // Extract the JAR plug-in entry form the eclipse archive + ZipEntry jarPluginEntry = eclipseArchive.getEntry(jarPluginRelativePath); + jarPluginInputStream = eclipseArchive.getInputStream(jarPluginEntry); + + JarInputStream inputStream = new JarInputStream(jarPluginInputStream); + + // Iterate through the plug-ins resources and store data on the properties files + JarEntry entry; + while (( entry = inputStream.getNextJarEntry() ) != null) { + String entryName = entry.getName(); + if (entryName.endsWith(Messages.getString("Extensions_properties"))) { //$NON-NLS-1$ + Properties properties = new Properties(); + properties.load(inputStream); + propertiesMap.put(entry.getName(), new HashSet<Object>(properties.keySet())); + } + } + inputStream.close(); + jarPluginInputStream.close(); + + return propertiesMap; + } + + public InputStream getResourceAsStream(ResourceProxy resource) + throws ZipException, IOException, FileNotFoundException, Exception { + + String resourcePath = Messages.getString("Paths_eclipse_directory_name") + SLASH + + (eclipseInstallPlugin.isFeature() ? "features" : "plugins") + + SLASH + eclipseInstallPlugin.getName() + Messages.getString("Characters_underscore") + + eclipseInstallPlugin.getVersion() + SLASH + resource.getCanonicalPath(); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ $NON-NLS-4$ + + ZipEntry resourceFile = eclipseArchive.getEntry(resourcePath); + if (resourceFile == null) { + return null; + } + return eclipseArchive.getInputStream(resourceFile); + } + + public boolean writeAboutHtmlFile(File resource, JarOutputStream out) throws Exception { + String pluginRelativePath = eclipseInstallPlugin.getPluginLocation().getAbsolutePath().replace(eclipseArchiveLocation.getAbsolutePath(), ""); + pluginRelativePath = pluginRelativePath.substring(1); + pluginRelativePath = pluginRelativePath.replace( + File.separator, Messages.getString("Characters_entry_separator")); //$NON-NLS-1$ + + ZipEntry archiveEntry; + if (eclipseInstallPlugin.isJar()) { + // Obtain an input stream for the jar resource + archiveEntry = eclipseArchive.getEntry(pluginRelativePath); + InputStream archiveInputStream = eclipseArchive.getInputStream(archiveEntry); + JarInputStream entryInputStream = new JarInputStream(archiveInputStream); + + // Find the about.html entry within the jar resource + JarEntry jarResourceEntry = entryInputStream.getNextJarEntry(); + boolean resourceFound = false; + while(jarResourceEntry != null && !resourceFound) { + String resourceEntryName = jarResourceEntry.getName(); + if (resourceEntryName.equalsIgnoreCase(resource.getName())) { + resourceFound = true; + } else { + jarResourceEntry = entryInputStream.getNextJarEntry(); + } + } + + // Add the file to the jar + out.putNextEntry(new JarEntry(jarResourceEntry.getName())); + writeToOutputStream(out, entryInputStream); + archiveInputStream.close(); + entryInputStream.close(); + } else { + // Obtain the about.html entry directly from the eclipse archive + archiveEntry = eclipseArchive.getEntry(pluginRelativePath + SLASH + resource.getName()); + out.putNextEntry(new ZipEntry(resource.getName())); + InputStream archiveInputStream = eclipseArchive.getInputStream(archiveEntry); + + // Add the file to the jar + writeToOutputStream(out, archiveInputStream); + archiveInputStream.close(); + } + + out.closeEntry(); + + return true; + } + + private void writeToOutputStream(OutputStream out, InputStream in) throws Exception { + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseInstallMediator.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseInstallMediator.java new file mode 100644 index 0000000..dc97553 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseInstallMediator.java
@@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipInputStream; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; + + +public class FragmentEclipseInstallMediator implements + FragmentEclipseTargetMediator { + + private PluginProxy eclipseInstallPlugin; + + public FragmentEclipseInstallMediator(PluginProxy eclipseInstallPlugin) { + this.eclipseInstallPlugin = eclipseInstallPlugin; + } + + public Map<String, Set<Object>> extractEclipseTargetProperties() throws ZipException, + IOException, FileNotFoundException { + + Map<String, Set<Object>> propertiesMap = new HashMap<String, Set<Object>>(); + InputStream jarPluginInputStream = new FileInputStream(eclipseInstallPlugin.getPluginLocation()); + + ZipInputStream inputStream = new ZipInputStream(jarPluginInputStream); + + ZipEntry entry; + while (( entry = inputStream.getNextEntry() ) != null) { + String entryName = entry.getName(); + if (entryName.endsWith(Messages.getString("Extensions_properties"))) { //$NON-NLS-1$ + Properties properties = new Properties(); + properties.load(inputStream); + propertiesMap.put(entry.getName(), new HashSet<Object>(properties.keySet())); + } + } + + return propertiesMap; + } + + public InputStream getResourceAsStream(ResourceProxy resource) throws ZipException, IOException, + FileNotFoundException { + + InputStream stream; + // If it's a resource that was in a jar resource file + if (!resource.getFileResource().exists()) { + + // Determine the resource's entry name within the jar + String entryPath = resource.getCanonicalPath(); + if (entryPath.contains(JAR_RESOURCE_SUFFIX + SLASH)) { + String target = entryPath.substring(0, entryPath.indexOf + (JAR_RESOURCE_SUFFIX + SLASH) + JAR_RESOURCE_SUFFIX.length()); + entryPath = entryPath.replace(target + SLASH, ""); //$NON-NLS-1$ + } + + // Determine the location of the jar resource file + int jarResourceEndIndex = resource.getFileResource().getAbsolutePath().indexOf(JAR_EXTENSION) + JAR_EXTENSION.length(); + String jarResourcePath = resource.getFileResource().getAbsolutePath().substring(0, jarResourceEndIndex); + + // Return an input stream of the resource entry within the jar + JarFile jarFile = new JarFile(new File(jarResourcePath)); + JarEntry resourceEntry = jarFile.getJarEntry(entryPath); + stream = jarFile.getInputStream(resourceEntry); + } else { + stream = new FileInputStream(resource.getFileResource()); + } + return stream; + } + + public boolean writeAboutHtmlFile(File resource, JarOutputStream out) throws Exception { + try { + ZipEntry newEntry; + InputStream inputStream; + + if (eclipseInstallPlugin.isJar()) { + JarFile pluginJar = new JarFile(this.eclipseInstallPlugin.getPluginLocation()); + newEntry = pluginJar.getJarEntry(ABOUT_FILE); + out.putNextEntry(newEntry); + inputStream = pluginJar.getInputStream(newEntry); + } else { + newEntry = new ZipEntry(resource.getName()); + out.putNextEntry(newEntry); + inputStream = new FileInputStream(resource); + } + + writeToOutputStream(out, inputStream); + + out.closeEntry(); + + return true; + } + catch(IOException e) { System.out.println(e.getMessage()); return false;} + } + + private void writeToOutputStream(JarOutputStream out, InputStream in) throws Exception { + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseTargetMediator.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseTargetMediator.java new file mode 100644 index 0000000..54b3e4c --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/eclipsetarget/FragmentEclipseTargetMediator.java
@@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.eclipsetarget; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Set; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipException; + +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.ResourceProxy; + + +public interface FragmentEclipseTargetMediator { + + public final String SLASH = Messages.getString("Characters_entry_separator"); //$NON-NLS-1$ + public final String JAR_RESOURCE_SUFFIX = Messages.getString("Suffixes_jar_resource_folder"); //$NON-NLS-1$ + public final String JAR_EXTENSION = Messages.getString("Extensions_jar"); //$NON-NLS-1$ + public final String ABOUT_FILE = Messages.getString("Paths_about_html"); //$NON-NLS-1$ + + public InputStream getResourceAsStream(ResourceProxy resource) throws ZipException, + IOException, FileNotFoundException, Exception; + + public Map<String, Set<Object>> extractEclipseTargetProperties() + throws ZipException, IOException, FileNotFoundException; + + public boolean writeAboutHtmlFile(File resource, JarOutputStream out) throws Exception; +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/FailedDeletionException.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/FailedDeletionException.java new file mode 100644 index 0000000..800ed24 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/FailedDeletionException.java
@@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.exceptions; + +public class FailedDeletionException extends Exception { + + static final long serialVersionUID = 3L; + + public FailedDeletionException() { + } + + public FailedDeletionException(String arg0) { + super(arg0); + } + + public FailedDeletionException(Throwable arg0) { + super(arg0); + } + + public FailedDeletionException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidFilenameException.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidFilenameException.java new file mode 100644 index 0000000..3a7c7dd --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidFilenameException.java
@@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.exceptions; + +public class InvalidFilenameException extends Exception { + + static final long serialVersionUID = 3L; + + public InvalidFilenameException() { + } + + public InvalidFilenameException(String arg0) { + super(arg0); + } + + public InvalidFilenameException(Throwable arg0) { + super(arg0); + } + + public InvalidFilenameException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidLocationException.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidLocationException.java new file mode 100644 index 0000000..b020030 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/InvalidLocationException.java
@@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.exceptions; + +public class InvalidLocationException extends Exception { + + static final long serialVersionUID = 3L; + + public InvalidLocationException() { + } + + public InvalidLocationException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidLocationException(Throwable cause) { + super(cause); + } + + public InvalidLocationException(String message) { + super(message); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/MissingLocationException.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/MissingLocationException.java new file mode 100644 index 0000000..03239a3 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/exceptions/MissingLocationException.java
@@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.exceptions; + +public class MissingLocationException extends Exception { + + static final long serialVersionUID = 4L; + + public MissingLocationException() { + } + + public MissingLocationException(String message) { + super(message); + } + + public MissingLocationException(Throwable cause) { + super(cause); + } + + public MissingLocationException(String message, Throwable cause) { + super(message, cause); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/JarNLFragment.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/JarNLFragment.java new file mode 100644 index 0000000..6babd19 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/JarNLFragment.java
@@ -0,0 +1,284 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.languagepack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.eclipsetarget.FragmentEclipseArchiveMediator; +import org.eclipse.babel.build.core.eclipsetarget.FragmentEclipseInstallMediator; +import org.eclipse.babel.build.core.eclipsetarget.FragmentEclipseTargetMediator; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + +/** + * + * Responsible for generating an NL Fragment as a jar in the language pack. + * + */ +public class JarNLFragment implements NLFragment { + + private File directory; + private PluginProxy eclipseInstallPlugin; + + private Map<String, Set<Object>> propertiesMap = new HashMap<String, Set<Object>>(); + private FragmentEclipseTargetMediator mediator; + + public JarNLFragment(File directory, PluginProxy eclipseInstallPlugin, EclipseTarget eclipseTarget) throws Exception { + this.directory = new File(directory.getAbsolutePath() + JAR_EXTENSION); + this.eclipseInstallPlugin = eclipseInstallPlugin; + if (eclipseTarget.isArchive()) { + mediator = new FragmentEclipseArchiveMediator(this.eclipseInstallPlugin, eclipseTarget.getLocation()); + } else { + mediator = new FragmentEclipseInstallMediator(this.eclipseInstallPlugin); + } + } + + public PluginCoverageInformation generateFragment(Configuration config) throws Exception { + + // Keeps track of whether or not the about.html file has been added to the fragment + boolean aboutAdded = false; + + TranslationCatalogue translationCatalogue = config.translations(); + Set <LocaleProxy> locales = config.locales(); + + // An empty list of locales means all of them should be parsed + if(locales.isEmpty() && config.localeGroups().isEmpty()) { + locales.addAll(translationCatalogue.getAllLocales()); + } + + Map<String, PluginProxy> translationCataloguePluginMap = + getPluginOrFeatureForSpecifiedLocales(config, eclipseInstallPlugin); + + // The output stream that will be used to write to the jar nl fragment + JarOutputStream out = null; + FileOutputStream fileOut = null; + + PluginCoverageInformation coverage = new PluginCoverageInformation(eclipseInstallPlugin); + + try { + /* If the eclipse target plug-in is a jar, then the set of properties for all + of its properties files are stored in a map for quick access, in order to avoid + having to open and close a stream for each properties file */ + if (this.eclipseInstallPlugin.isJar()) { + this.propertiesMap = mediator.extractEclipseTargetProperties(); + } + + for(LocaleProxy locale: locales) { + + boolean pluginIsMatchedToThisLocale = + translationCataloguePluginMap.containsKey(locale.getName()); + + if ( pluginIsMatchedToThisLocale ) { + PluginProxy translationArchivePlugin = + translationCataloguePluginMap.get(locale.getName()); + + for(ResourceProxy resource: eclipseInstallPlugin.getResources()){ + //If the resource is the about.html file + if (resource.getRelativePath().equalsIgnoreCase(ABOUT_FILE) && !aboutAdded) { + if(out == null) { + fileOut = new FileOutputStream(directory); + out = new JarOutputStream(fileOut, composeManifestContent(config.localeExtension())); + } + aboutAdded = mediator.writeAboutHtmlFile(resource.getFileResource(), out); + } + //Want to make sure that this block of code is not executed for a Manifest file + else if (!resource.getRelativePath().equalsIgnoreCase(MANIFEST_PATH)) { + ResourceProxy translationResource = translationCatalogue. + getResourceTranslation(translationArchivePlugin, resource); + + if(translationResource != null) { + if(out == null) { + fileOut = new FileOutputStream(directory); + out = new JarOutputStream(fileOut, composeManifestContent(config.localeExtension())); + } + writeResource(out, translationResource, locale); + + if (resource.getRelativePath().endsWith(Messages.getString("Extensions_properties"))) { //$NON-NLS-1$ + // If the resource is a properties file, then compute property coverage + int value = computePropertyCoverageForLocale(resource, translationResource); + coverage.setResourceCoverageForLocale(locale, resource, true, value); + } + else { + //Mark that this resource has been matched for this locale + coverage.setResourceCoverageForLocale(locale, resource, true); + } + } + else { + //Mark that this resource has NOT been matched for this locale + coverage.setResourceCoverageForLocale(locale, resource, false); + } + } + } + } + coverage.setPluginMatchingForLocale(locale, pluginIsMatchedToThisLocale); + } + // Complete the ZIP file + if(out != null) { + out.close(); + fileOut.close(); + } + } + catch (IOException e) { + System.out.println(e.getMessage()); + } + + return coverage; + } + + private int computePropertyCoverageForLocale(ResourceProxy eclipseTargetResource, ResourceProxy translationResource) throws Exception { + // Load the set of properties within the translated resource + InputStream transIn = new FileInputStream(translationResource.getFileResource()); + Properties transProperty = new Properties(); + transProperty.load(transIn); + + // Load the set of properties within the eclipse target resource + Set<Object> properties; + if (this.eclipseInstallPlugin.isJar()) { + properties = new HashSet<Object>(this.propertiesMap.get(eclipseTargetResource.getCanonicalPath())); + } else { + InputStream in = mediator.getResourceAsStream(eclipseTargetResource); + Properties property = new Properties(); + if (in != null) { + property.load(in); + in.close(); + } + properties = new HashSet<Object>(property.keySet()); + } + transIn.close(); + + // Compute the amount of eclipse target resource properties covered by the translation resource + int initialSize = properties.size(); + initialSize = initialSize < 1 ? 1 : initialSize; + properties.removeAll(transProperty.keySet()); + return (100*(initialSize - properties.size()))/initialSize; + } + + private Manifest composeManifestContent(String localeExtension) throws Exception { + Manifest manifest = new Manifest(); + + Attributes attributes = manifest.getMainAttributes(); + + attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_name"), eclipseInstallPlugin.getName() + " " + Messages.getString("Suffixes_fragment_name")); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ + attributes.putValue(Messages.getString("Manifest_key_bundle_version"), eclipseInstallPlugin.getVersion()); //$NON-NLS-1$ + attributes.putValue( Messages.getString("Manifest_key_bundle_symbolic_name"), eclipseInstallPlugin.getName() + + Messages.getString("Extensions_nl") + localeExtension + Messages.getString("Manifest_value_bundle_symbolic_name_suffix") ); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ + + if ( eclipseInstallPlugin.getName().contains(( Messages.getString("Prefixes_eclipse_plugin") )) ) { //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_eclipse")); //$NON-NLS-1$ $NON-NLS-2$ + } else if ( eclipseInstallPlugin.getName().contains(( Messages.getString("Prefixes_ibm_plugin") )) ) { //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_ibm")); //$NON-NLS-1$ $NON-NLS-2$ + } else { + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_unknown")); //$NON-NLS-1$ $NON-NLS-2$ + } + + attributes.putValue(Messages.getString("Manifest_key_fragment_host"), eclipseInstallPlugin.getName()); //$NON-NLS-1$ + + return manifest; + } + + private boolean writeResource(JarOutputStream out, + ResourceProxy translationResource, LocaleProxy locale) { + try { + byte[] buf = new byte[1024]; + FileInputStream in = new FileInputStream(new File(translationResource.getFileResource().getAbsolutePath())); + + // The path of the resource entry in the language pack + String temp = determineTranslatedResourceName(translationResource, locale); + temp = temp.replace(File.separator, Messages.getString("Characters_entry_separator")); //$NON-NLS-1$ + + // Add ZIP entry to output stream. + out.putNextEntry(new JarEntry(temp)); + + // Transfer bytes from the translation archive file to the new language pack ZIP file + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + // Complete the entry + out.closeEntry(); + in.close(); + return true; + } catch (IOException e) { + System.out.println(e.getMessage()); + return false; + } + } + + public String determineTranslatedResourceName(ResourceProxy resource, LocaleProxy locale) { + String resourceName = resource.getRelativePath(); + + /* If the resource was held in a jar resource within the plug-in, then the place-holder + directory representing the jar resource (usually called pluginName_jar) must be removed + from the path */ + if (resourceName.contains(JAR_RESOURCE_SUFFIX + File.separator)) { + String target = resourceName.substring(0, resourceName.indexOf + (JAR_RESOURCE_SUFFIX + File.separator) + JAR_RESOURCE_SUFFIX.length()); + resourceName = resourceName.replace(target + File.separator, ""); //$NON-NLS-1$ + } + + String resourceExtension = resourceName.substring( + resourceName.lastIndexOf(Messages.getString("Characters_period"))); //$NON-NLS-1$ + return resourceName.substring(0, resourceName.lastIndexOf(Messages.getString("Characters_period"))) + + Messages.getString("Characters_underscore") + locale.getName() + resourceExtension; //$NON-NLS-1$ $NON-NLS-2$ + } + + private Map<String, PluginProxy> getPluginOrFeatureForSpecifiedLocales(Configuration config, PluginProxy plugin) { + if (plugin.isFeature()) { + return config.translations().getFeatureForSpecifiedLocales(plugin); + } + return config.translations().getPluginForSpecifiedLocales(plugin); + } + /* + private String incrementRelease(String oldVersion) { + if (oldVersion.matches(VERSION_FORMAT_WITH_QUALIFIER)) { + oldVersion = oldVersion.substring(0, oldVersion.lastIndexOf(PERIOD)); + } + + String newVersion = LEFT_SQUARE_BRACKET + oldVersion + ','; + String oldMinor = oldVersion.substring(oldVersion.indexOf(PERIOD) + 1, oldVersion.lastIndexOf(PERIOD)); + String oldMicro = oldVersion.substring(oldVersion.lastIndexOf(PERIOD) + 1); + + if (oldMinor.compareTo(MAX_MINOR) == 0) { + String major = Integer.toString(Integer.parseInt(oldVersion.substring(0, oldVersion.indexOf(PERIOD))) + 1); + newVersion += major + PERIOD + MIN_MINOR + PERIOD + oldMicro + RIGHT_PARENTHESIS; + } else { + String major = oldVersion.substring(0, oldVersion.indexOf(PERIOD)); + String newMinor = Integer.toString(Integer.parseInt(oldMinor) + 1); + newVersion += major + PERIOD + newMinor + PERIOD + oldMicro + RIGHT_PARENTHESIS; + } + + return newVersion; + } + */ + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/LanguagePack.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/LanguagePack.java new file mode 100644 index 0000000..5abf902 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/LanguagePack.java
@@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.languagepack; + +import java.io.File; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.exceptions.FailedDeletionException; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; + +public class LanguagePack { + + private Configuration config; + private File absoluteWorkDirectory; + + public LanguagePack(Configuration config) { + this.config = config; + } + + /** Generates a language pack on disk and returns a report with coverage information. */ + public LanguagePackCoverageReport generate() throws InvalidFilenameException, FailedDeletionException, Exception { + NLFragment fragment; + File parentFragmentDirectory; + EclipseTarget eclipseInstall = config.eclipseInstall(); + LanguagePackCoverageReport coverage; + + this.absoluteWorkDirectory = this.config.workingDirectory().getAbsoluteFile(); + setupLanguagePackLocation(); + + coverage = new LanguagePackCoverageReport(config.translations().getAllLocales()); + + //For each plugin in the eclipse archive + for(PluginProxy plugin: eclipseInstall.getPlugins().values()) { + + String versionSuffix = ""; + if (!plugin.getVersion().equalsIgnoreCase("")) { + versionSuffix = Messages.getString("Characters_underscore") + plugin.getVersion(); + } + + //Determine the file path in the language pack directory for this plug-in + parentFragmentDirectory = new File(this.absoluteWorkDirectory.getAbsoluteFile() + + File.separator + Messages.getString("Paths_plugins_directory") + plugin.getName() + + Messages.getString("Extensions_nl") + config.localeExtension() + versionSuffix); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ + + config.notifyProgress(plugin.getName()); + + // At present, all NL fragments are jarred + fragment = new JarNLFragment(parentFragmentDirectory, plugin, eclipseInstall); + + coverage.addPluginCoverageToReport( fragment.generateFragment(this.config) ); + } + + //For each feature in the eclipse archive + for(PluginProxy feature: eclipseInstall.getFeatures().values()) { + + String versionSuffix = ""; + if (!feature.getVersion().equalsIgnoreCase("")) { + versionSuffix = Messages.getString("Characters_underscore") + feature.getVersion(); + } + + //Determine the file path in the language pack directory for this feature + parentFragmentDirectory = new File(this.absoluteWorkDirectory.getAbsoluteFile() + + File.separator + Messages.getString("Paths_features_directory") + feature.getName() + + Messages.getString("Extensions_nl") + config.localeExtension() + versionSuffix); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + config.notifyProgress(feature.getName()); + + //TODO: Determine if feature fragments should be jarred or not + //Instantiate the new fragment with its directory, and generate it + if(!feature.isJar()) { + fragment = new NonJarNLFragment(parentFragmentDirectory, feature); + } + else { + fragment = new JarNLFragment(parentFragmentDirectory, feature, eclipseInstall); + } + coverage.addPluginCoverageToReport( fragment.generateFragment(this.config) ); + } + + return coverage; + } + + private void setupLanguagePackLocation() throws InvalidFilenameException, FailedDeletionException { + + if (this.absoluteWorkDirectory.exists()) + { + try { + File eclipseFolder = new File(this.absoluteWorkDirectory, Messages.getString("Paths_eclipse_directory_name")); //$NON-NLS-1$ + if (eclipseFolder.exists()) { + //Find and remove eclipse folder in working directory folder (if exists) + for (File file: eclipseFolder.listFiles()) { + deleteDirectory(file); + } + } + } catch (Exception e) { + throw new FailedDeletionException(); + } + + } else { + this.absoluteWorkDirectory.mkdirs(); + } + generateBaseFolders(); + } + + private void generateBaseFolders() { + File newDirectory = new File(this.absoluteWorkDirectory + File.separator + Messages.getString("Paths_plugins_directory")); //$NON-NLS-1$ + newDirectory.mkdirs(); + + newDirectory = new File(this.absoluteWorkDirectory + File.separator + Messages.getString("Paths_features_directory")); //$NON-NLS-1$ + newDirectory.mkdirs(); + } + + private boolean deleteDirectory(File path) { + if( path.exists() ) { + File[] files = path.listFiles(); + for(int i=0; i<files.length; i++) { + if(files[i].isDirectory()) { + deleteDirectory(files[i]); + } + else { + files[i].delete(); + } + } + } + return( path.delete() ); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NLFragment.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NLFragment.java new file mode 100644 index 0000000..a595b9e --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NLFragment.java
@@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.languagepack; + +import java.io.File; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; + + + +public interface NLFragment { + + public final String META_INF_DIR_NAME = Messages.getString("Paths_meta_inf_directory"); //$NON-NLS-1$ + public final String MANIFEST_FILE_NAME = Messages.getString("Filename_manifest"); //$NON-NLS-1$ + public final String MANIFEST_PATH = META_INF_DIR_NAME + File.separator + MANIFEST_FILE_NAME; + public final String MANIFEST_ASSIGN = Messages.getString("Characters_manifest_assign") + " "; //$NON-NLS-1$ $NON-NLS-2$ + public final String SLASH = Messages.getString("Characters_entry_separator"); //$NON-NLS-1$ + public final String JAR_RESOURCE_SUFFIX = Messages.getString("Suffixes_jar_resource_folder"); //$NON-NLS-1$ + public final String JAR_EXTENSION = Messages.getString("Extensions_jar"); //$NON-NLS-1$ + public final String ABOUT_FILE = Messages.getString("Paths_about_html"); //$NON-NLS-1$ + + /* + public final String PERIOD = "."; //$NON-NLS-1$ + public final String MIN_MINOR = "0"; //$NON-NLS-1$ + public final String MAX_MINOR = "9"; //$NON-NLS-1$ + public final String LEFT_SQUARE_BRACKET = "["; //$NON-NLS-1$ + public final String RIGHT_PARENTHESIS = ")"; //$NON-NLS-1$ + public final String DEFAULT_VERSION = "1.0.0"; //$NON-NLS-1$ + public final String VERSION_FORMAT_WITH_QUALIFIER = "\\d+\\.\\d+\\.\\d+\\..+"; //$NON-NLS-1$ + */ + + /** Generates an NLFragment for a specific plug-in, and returns coverage information about that plug-in. */ + public PluginCoverageInformation generateFragment(Configuration config) throws Exception; + + /** Given a resource and locale, determines name of the resource generated in the language pack. */ + public String determineTranslatedResourceName(ResourceProxy resource, LocaleProxy locale); +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NonJarNLFragment.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NonJarNLFragment.java new file mode 100644 index 0000000..9a506e4 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/languagepack/NonJarNLFragment.java
@@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.languagepack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.channels.FileChannel; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + +/** + * + * Responsible for generating an NL Fragment as a directory in the language pack. + * May be removed in the near future if it is confirmed that all nl fragments should be jars. + * + */ +public class NonJarNLFragment implements NLFragment { + + private File directory; + private final String BUNDLE_CLASSPATH = Messages.getString("Filename_bundle_classpath"); //$NON-NLS-1$ + private JarOutputStream bundleClasspathStream = null; + private PluginProxy eclipseInstallPlugin; + + public NonJarNLFragment(File directory, PluginProxy eclipseInstallPlugin ) { + this.directory = directory; + this.eclipseInstallPlugin = eclipseInstallPlugin; + } + + public PluginCoverageInformation generateFragment(Configuration config) throws Exception { + + directory.mkdir(); + + TranslationCatalogue translationCatalogue = config.translations(); + Set <LocaleProxy> locales = config.locales(); + + //An empty list of locales means all of them should be parsed + if(locales.isEmpty() && config.localeGroups().isEmpty()) { + locales.addAll(translationCatalogue.getAllLocales()); + } + + Map<String, PluginProxy> translationCataloguePluginMap = + getPluginOrFeatureForSpecifiedLocales(config, eclipseInstallPlugin); + + boolean pluginIsMatchedToAnyLocale = false; + + PluginCoverageInformation coverage = new PluginCoverageInformation(eclipseInstallPlugin); + + try { + for(LocaleProxy locale: locales) { + //Start by inspecting the plug-ins + boolean pluginIsMatchedToThisLocale = + translationCataloguePluginMap.containsKey(locale.getName()); + + if ( pluginIsMatchedToThisLocale ) { + PluginProxy translationCataloguePlugin = + translationCataloguePluginMap.get(locale.getName()); + pluginIsMatchedToAnyLocale = true; + + //For all the resources of the plug-in from the eclipse archive + for(ResourceProxy resource: eclipseInstallPlugin.getResources()){ + //If the resource is the Manifest file + if(resource.getRelativePath().equalsIgnoreCase(MANIFEST_PATH)) { + FileOutputStream fileOut = new FileOutputStream(new File (directory, MANIFEST_PATH)); + Manifest manifest = composeManifestContent(config.localeExtension()); + manifest.write(fileOut); + } + else { + //Retrieve the translation resource + ResourceProxy translationResource = translationCatalogue. + getResourceTranslation(translationCataloguePlugin, resource); + + /* + * Write the resource... if the object is not null, that means + * that a corresponding resource was found in the TranslationArchive + */ + if(translationResource != null) { + writeResource(eclipseInstallPlugin, translationResource, locale); + + //TODO: Look for percentage of coverage for property files only + if (resource.getRelativePath().endsWith(Messages.getString("Extensions_properties"))) { //$NON-NLS-1$ + + int value = computePropertyCoverageForLocale(config, resource, translationResource); + coverage.setResourceCoverageForLocale(locale, resource, true, value); + } + else { + //Mark that this resource has been matched for this locale + coverage.setResourceCoverageForLocale(locale, resource, true); + } + } + else { + //Mark that this resource has NOT been matched for this locale + coverage.setResourceCoverageForLocale(locale, resource, false); + } + } + } + } + coverage.setPluginMatchingForLocale(locale, pluginIsMatchedToThisLocale); + + } + + if(!pluginIsMatchedToAnyLocale) { + directory.delete(); + } + + if (bundleClasspathStream != null) { + bundleClasspathStream.close(); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + return coverage; + } + + private int computePropertyCoverageForLocale(Configuration config, ResourceProxy eclipseTargetResource, ResourceProxy translationResource) throws Exception { + InputStream in = getResourceAsStream(config, eclipseTargetResource); + Properties property = new Properties(); + property.load(in); + + InputStream transIn = new FileInputStream(translationResource.getFileResource()); + Properties transProperty = new Properties(); + transProperty.load(transIn); + + Set<Object> properties = new HashSet<Object>(property.keySet()); + int initialSize = properties.size(); + initialSize = initialSize < 1 ? 1 : initialSize; + properties.removeAll(transProperty.keySet()); + return (100*(initialSize - properties.size()))/initialSize; + } + + private InputStream getResourceAsStream(Configuration config, + ResourceProxy resource) throws ZipException, IOException, + FileNotFoundException { + + if (config.eclipseInstall().isArchive()) { + ZipFile eclipseArchive = new ZipFile(config.eclipseInstall().getLocation()); + + String pluginPath = Messages.getString("Paths_eclipse_directory_name") + SLASH + + (eclipseInstallPlugin.isFeature() ? "features" : "plugins") + + SLASH + eclipseInstallPlugin.getName()+ Messages.getString("Characters_underscore") + + eclipseInstallPlugin.getVersion() + SLASH + resource.getCanonicalPath(); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ $NON-NLS-4$ + + ZipEntry resourceFile = eclipseArchive.getEntry(pluginPath); + return eclipseArchive.getInputStream(resourceFile); + } + + return new FileInputStream(resource.getFileResource()); + } + /** + private void addBundleClasspathInManifest(Manifest manifest) throws Exception { + Manifest manifest = new Manifest(); + + Attributes attributes = manifest.getMainAttributes(); + + attributes.putValue(Messages.getString("Manifest_entry_bundle_classpath"), Messages.getString("Filename_bundle_classpath")); //$NON-NLS-1$ $NON-NLS-2$ + }*/ + + private Manifest composeManifestContent(String localeExtension) throws Exception { + Manifest manifest = new Manifest(); + + Attributes attributes = manifest.getMainAttributes(); + + attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_name"), eclipseInstallPlugin.getName() + " " + Messages.getString("Suffixes_fragment_name")); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ + attributes.putValue(Messages.getString("Manifest_key_bundle_version"), eclipseInstallPlugin.getVersion()); //$NON-NLS-1$ + attributes.putValue( Messages.getString("Manifest_key_bundle_symbolic_name"), eclipseInstallPlugin.getName() + + Messages.getString("Extensions_nl") + localeExtension + Messages.getString("Manifest_value_bundle_symbolic_name_suffix") ); //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$ + + if ( eclipseInstallPlugin.getName().contains(( Messages.getString("Prefixes_eclipse_plugin") )) ) { //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_eclipse")); //$NON-NLS-1$ $NON-NLS-2$ + } else if ( eclipseInstallPlugin.getName().contains(( Messages.getString("Prefixes_ibm_plugin") )) ) { //$NON-NLS-1$ + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_ibm")); //$NON-NLS-1$ $NON-NLS-2$ + } else { + attributes.putValue(Messages.getString("Manifest_key_bundle_vendor"), Messages.getString("Provider_name_unknown")); //$NON-NLS-1$ $NON-NLS-2$ + } + + attributes.putValue(Messages.getString("Manifest_key_fragment_host"), eclipseInstallPlugin.getName()); //$NON-NLS-1$ + + return manifest; + } + + private boolean writeResource(PluginProxy eclipseInstallPlugin, ResourceProxy translation, LocaleProxy locale) throws Exception { + String translationResourceName = determineTranslatedResourceName(translation, locale); + String pluginNameInDirFormat = eclipseInstallPlugin.getName().replace(Messages.getString("Characters_period"), File.separator); //$NON-NLS-1$ + + if(translation.getRelativePath().contains(pluginNameInDirFormat)) { + return writeResourceToBundleClasspath(translation, locale); + } + else if (translationResourceName.contains(File.separator)) { + String resourcePath = translationResourceName.substring(0, translationResourceName.lastIndexOf(File.separatorChar)); + File resourcePathDirectory = new File(directory.getPath() + File.separatorChar + resourcePath); + resourcePathDirectory.mkdirs(); + } + + File fragmentResource = new File(directory.getPath() + File.separatorChar + translationResourceName); + File translatedResource = new File(translation.getFileResource().getAbsolutePath()); + + FileChannel inputChannel = new FileInputStream(translatedResource).getChannel(); + FileChannel outputChannel = new FileOutputStream(fragmentResource).getChannel(); + inputChannel.transferTo(0, inputChannel.size(), outputChannel); + inputChannel.close(); + outputChannel.close(); + return true; + } + + private boolean writeResourceToBundleClasspath(ResourceProxy translation, LocaleProxy locale) throws Exception { + if (bundleClasspathStream == null) { + bundleClasspathStream = new JarOutputStream( + new FileOutputStream(directory.getPath() + File.separator + BUNDLE_CLASSPATH)); + } + + byte[] buf = new byte[1024]; + + FileInputStream in = new FileInputStream(new File(translation.getFileResource().getAbsolutePath())); + + // The path of the resource entry in the language pack + String temp = determineTranslatedResourceName(translation, locale); + + // Add ZIP entry to output stream. + bundleClasspathStream.putNextEntry(new ZipEntry(temp)); + + // Transfer bytes from the translation archive file to the new language pack ZIP file + int len; + while ((len = in.read(buf)) > 0) { + bundleClasspathStream.write(buf, 0, len); + } + + // Complete the entry + bundleClasspathStream.closeEntry(); + in.close(); + return true; + } + + public String determineTranslatedResourceName(ResourceProxy resource, + LocaleProxy locale) { + String resourceName = resource.getRelativePath(); + String resourceExtension = resourceName.substring(resourceName.lastIndexOf(Messages.getString("Characters_period"))); //$NON-NLS-1$ + return resourceName.substring(0, resourceName.lastIndexOf(Messages.getString("Characters_period"))) //$NON-NLS-1$ + + Messages.getString("Characters_underscore") + locale.getName() + resourceExtension; //$NON-NLS-1$ + } + + private Map<String, PluginProxy> getPluginOrFeatureForSpecifiedLocales(Configuration config, PluginProxy plugin) { + if (plugin.isFeature()) { + return config.translations().getFeatureForSpecifiedLocales(plugin); + } + return config.translations().getPluginForSpecifiedLocales(plugin); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/messages.properties b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/messages.properties new file mode 100644 index 0000000..0a9a41d --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/messages.properties
@@ -0,0 +1,101 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +Characters_entry_separator=/ +Characters_locale_token=, +Characters_manifest_assign=: +Characters_newline=\n +Characters_period=. +Characters_underscore=_ + +Error_eclipse_target=Error parsing eclipse target. +Error_deleting_working_directory=Error clearing the eclipse folder in the work directory. Please clear the eclipse folder before proceeding with another run. +Error_invalid_eclipse_target=Error parsing eclipse target. Please verify that the specified target is a valid eclipse target with the proper directory structure. +Error_invalid_translation_catalogue=Error parsing translation catalogue. No matching translations were found. Please verify that the specified locale folders are directly inside the specified translation catalogue location. +Error_invalid_translation_catalogue_bulk=Error parsing translation catalogue. No matching translations were found. Please verify that the locale group folders are directly inside the specified translation catalogue location. +Error_invalid_eclipse_target_name=Error parsing eclipse target. Please verify that the specified target path is structured properly. +Error_invalid_translation_catalogue_name=Error parsing translation catalogue. Please verify that the translation catalogue path is structured properly. +Error_invalid_working_directory_name=Error generating language pack. Please verify that the specified working directory path is structured properly. +Error_missing_eclipse_target=Error parsing eclipse target. Please verify that the specified target exists at the given location. +Error_missing_translation_catalogue=Error parsing translation catalogue. Please verify that the translation catalogue exists at the given location. +Error_language_pack=Error generating language pack. +Error_log_coverage_report=Error logging coverage report. +Error_missing_argument=Missing argument: +Error_unset_mandatory_exception=Unset mandatory argument: + +Extensions_class=.*\.class +Extensions_properties=.properties +Extensions_jar=.jar +Extensions_java=.*\.java +Extensions_nl=.nl +Extensions_zip=.zip + +Filename_bundle_classpath=nl1.jar +Filename_manifest=MANIFEST.MF + +Groups_group1=gr1 +Groups_group2=gr2 +Groups_group2a=gr2a +Groups_groupBidi=grBidi +Groups_all=all + +Groups_group1_full=Group1 +Groups_group2_full=Group2 +Groups_group2a_full=Group2a +Groups_groupBidi_full=GroupBidi +Groups_all_full=All + +Masks_plugin=XXXXXXXXXXX + +Messages_generating_language_pack=Building Language Pack... +Messages_parsing_eclipse_target=Parsing Eclipse Target... + +Manifest_entry_bundle_classpath=Bundle-ClassPath + +Manifest_key_bundle_name=Bundle-Name +Manifest_key_bundle_symbolic_name=Bundle-SymbolicName +Manifest_key_bundle_version=Bundle-Version +Manifest_key_bundle_vendor=Bundle-Vendor +Manifest_key_fragment_host=Fragment-Host +Manifest_key_value_version=Manifest-Version: 1.0 +Manifest_value_bundle_symbolic_name_suffix=;singleton=true + +Paths_eclipse_directory_name=eclipse +Paths_features_directory=eclipse/features/ +Paths_meta_inf_directory=META-INF +Paths_plugins_directory=eclipse/plugins/ +Paths_eclipse_executable_entry=eclipse/eclipse.exe +Paths_about_html=about.html + +Patterns_plugin_name=.*_(\\d|\\.)+.* +Patterns_non_jar_plugin=.*/ +Patterns_suffixes_source=.*src\.zip + +Prefixes_eclipse_plugin=org.eclipse +Prefixes_ibm_plugin=com.ibm + +Properties_fragment_name=nlFragmentName= +Properties_provider_name=nlProviderName= + +Provider_name_eclipse=Eclipse.org +Provider_name_ibm=IBM Corporation +Provider_name_unknown=N/A + +Suffixes_directory=/ +Suffixes_fragment_name=NLS Support +Suffixes_jar_resource_folder=_jar + +Test_eclipse_install_location=C:\\eclipse-SDK-3.4.1-win32 +Test_eclipse_archive_install_location=C:\\eclipse-SDK-3.4.1-win32.zip +Test_raw_coverage_report_name=output.txt +Test_translation_catalogue_location=C:\\ies\\IES_3.3\\piiDocTransDir +Test_working_directory_location=C:\\EclipseTesting + +
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/CoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/CoverageReport.java new file mode 100644 index 0000000..08d2ffe --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/CoverageReport.java
@@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.reports; + +import java.io.OutputStream; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.coverage.ResourceCoverageInformation; + + +public interface CoverageReport { + public static class utils{ + public static final int calculateCoverageScore(LocaleProxy locale, ResourceProxy resource, PluginCoverageInformation info){ + ResourceCoverageInformation resourceInfo = info.getResourceCoverage().get(resource.getRelativePath()); + + if(resourceInfo == null){ + return 0; + } + + Boolean matchingForLocale = resourceInfo.getMatchingForLocale(locale); + if(matchingForLocale == null){ + return 0; + } + + Integer coverage = resourceInfo.getMatchedPercentageForLocale(locale); + if(coverage != null){ + return coverage; + } + + return matchingForLocale ? 100 : 0; + } + } + + public void render(OutputStream stream) throws Exception; +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/HtmlCoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/HtmlCoverageReport.java new file mode 100644 index 0000000..26a1f29 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/HtmlCoverageReport.java
@@ -0,0 +1,307 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.reports; + +import static org.eclipse.babel.build.core.xml.Builder.*; +import static org.eclipse.babel.build.core.xml.Html.*; + + +import java.io.OutputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.coverage.ResourceCoverageInformation; +import org.eclipse.babel.build.core.xml.Element; +import org.eclipse.babel.build.core.xml.XmlWriter; +import org.eclipse.babel.build.core.xml.Builder.ToNode; + + +public class HtmlCoverageReport implements CoverageReport{ + public class RollUpForLocale implements ToNode<LocaleProxy> { + + private final PluginCoverageInformation info; + private final PluginProxy plugin; + + public RollUpForLocale(PluginCoverageInformation info) { + this.info = info; + this.plugin = info.getEclipseArchivePlugin(); + } + + public Element toNode(LocaleProxy t) { + int min = Integer.MAX_VALUE; + + for(ResourceProxy resource : plugin.getResources()){ + boolean matched = resourceMatched(info, resource); + boolean included = config.includeResource(plugin, resource); + int score = CoverageReport.utils.calculateCoverageScore(t, resource, info); + + if(matched && included && score < min){ + min = score; + } + } + + return td("" + min).attribute("class", "" + completeness(min)); + } + + } + + public class PluginSummaryRow implements ToNode<PluginCoverageInformation>{ + public Element toNode(PluginCoverageInformation info) { + PluginProxy plugin = info.getEclipseArchivePlugin(); + + if(!hasMatchedResources(info)){ + return Element.utils.EMPTY_ELEMENT; + } + + return tr( + td(a("#" + plugin.getName(), plugin.getName())).attribute("class", "first"), + sequence(locales, new RollUpForLocale(info)) + ); + } + } + + public class UnmatchedResource implements ToNode<ResourceProxy> { + private PluginProxy plugin; + private final PluginCoverageInformation info; + + public UnmatchedResource(PluginCoverageInformation info){ + this.info = info; + this.plugin = info.getEclipseArchivePlugin(); + } + + public Element toNode(ResourceProxy resource) { + boolean matched = resourceMatched(info, resource); + boolean included = config.includeResource(plugin, resource); + + if(matched || !included){ + return Element.utils.EMPTY_ELEMENT; + } + + return li(resource.getRelativePath()); + } + + } + + + public class UnmatchedResourceList implements + ToNode<PluginCoverageInformation> { + + public Element toNode(PluginCoverageInformation info) { + PluginProxy plugin = info.getEclipseArchivePlugin(); + + if(hasMatchedResources(info)){ + return Element.utils.EMPTY_ELEMENT; + } + + return nodes( + h2(plugin.getName()), + ul(sequence(plugin.getResources(), new UnmatchedResource(info))) + ); + } + + } + + + private final class ResourceCoverageRow implements ToNode<ResourceProxy> { + private final PluginCoverageInformation info; + private final PluginProxy plugin; + + private ResourceCoverageRow(PluginCoverageInformation info) { + this.info = info; + plugin = info.getEclipseArchivePlugin(); + } + + public Element toNode(final ResourceProxy resource) { + if(!config.includeResource(plugin, resource)){ + return Element.utils.EMPTY_ELEMENT; + } + + if(!resourceMatched(info, resource)){ + return Element.utils.EMPTY_ELEMENT; + } + + return tr( + td(resource.getRelativePath()).attribute("class", "first"), + sequence(locales, new ToNode<LocaleProxy>(){ + public Element toNode(LocaleProxy locale) { + int score = CoverageReport.utils.calculateCoverageScore(locale, resource, info); + return td("" + score ).attribute("class", completeness(score)); + } + }) + ); + } + } + + private static String completeness(int score){ + if(score < 25){ + return "missing"; + } + + if(score < 80){ + return "incomplete"; + } + + if(score < 100){ + return "almost-complete"; + } + + return "complete"; + } + + private final class MatchedPluginCoverageTable implements ToNode<PluginCoverageInformation> { + public Element toNode(final PluginCoverageInformation info) { + if(!hasMatchedResources(info)){ + return Element.utils.EMPTY_ELEMENT; + } + + + PluginProxy plugin = info.getEclipseArchivePlugin(); + String name = plugin.getName(); + return nodes( + h2(a("#" + name, name).attribute("name", name).attribute("class", "target")), + table( + tr(th("Resource").attribute("class", "first"), sequence(locales, new ToNode<LocaleProxy>(){ + public Element toNode(LocaleProxy t) { + return th(t.getName()); + } + })), + sequence(plugin.getResources(), new ResourceCoverageRow(info)) + ) + ); + } + } + + + private static final String TITLE = "Language Pack Coverage Report"; + private final LanguagePackCoverageReport coverage; + private final Configuration config; + private final List<LocaleProxy> locales; + + public HtmlCoverageReport(Configuration config, LanguagePackCoverageReport coverage){ + this.config = config; + this.coverage = coverage; + this.locales = sorted(config.locales(), LocaleProxy.NAME_COMPARATOR); + } + + + public boolean hasMatchedResources(PluginCoverageInformation info) { + for(ResourceCoverageInformation coverage : info.getResourceCoverage().values()){ + boolean included = config.includeResource(info.getEclipseArchivePlugin(), coverage.getResource()); + boolean matched = resourceMatched(info, coverage.getResource()); + + if(included && matched){ + return true; + } + } + + return false; + } + + + private boolean resourceMatched(PluginCoverageInformation info, ResourceProxy resource) { + ResourceCoverageInformation coverage = info.getResourceCoverage().get(resource.getCanonicalPath()); + + if(coverage == null){ + return false; + } + return any(coverage.getLocaleMatchMap().values()); + } + + + private boolean any(Collection<Boolean> values) { + for(Boolean value : values){ + if(value != null && value){ + return true; + } + } + + return false; + } + + private static final int HEADER_WIDTH = 30; + private static final int CELL_WIDTH = 4; + + public Element build() { + return html( + head( + title(TITLE), + style( + "tr, th, td, table { border: 1px solid; }\n" + + ".missing { background-color: #FFBFBF; }\n" + + ".incomplete { background-color: #FFE6BF; }\n" + + ".almost-complete { background-color: #FFFFBF; }\n" + + ".complete { background-color: #BFFFBF; }\n" + + "a.target { color: black; }\n" + + String.format(".first { width: %dem; }\n", HEADER_WIDTH) + + String.format("th, td { width: %dem; }\n", CELL_WIDTH) + + String.format("table { table-layout: fixed; width: %dem; }", HEADER_WIDTH + locales.size() * CELL_WIDTH) + ) + ), + body( + h1(TITLE), + h2("Plugin Coverage Summary Table"), + table( + tr(th("Plugin Name").attribute("class", "first"), sequence(locales, new ToNode<LocaleProxy>(){ + public Element toNode(LocaleProxy t) { + return th(t.getName()); + } + })), + sequence(sorted(coverage.getPluginCoverageReports(), PluginCoverageInformation.NAME_COMPARATOR), new PluginSummaryRow()) + ), + + sequence( + sorted(coverage.getPluginCoverageReports(), PluginCoverageInformation.NAME_COMPARATOR), + new MatchedPluginCoverageTable() + ), + unmatchedResources() + ) + ); + } + + private Element unmatchedResources() { + if(!config.longReport()){ + return Element.utils.EMPTY_ELEMENT; + } + + return nodes( + h1("Unmatched Resources"), + sequence( + sorted(coverage.getPluginCoverageReports(), PluginCoverageInformation.NAME_COMPARATOR), + new UnmatchedResourceList() + ) + ); + } + + + private static <T> List<T> sorted(Iterable<T> ts, Comparator<T> cmp) { + List<T> list = new LinkedList<T>(); + for(T t : ts){ + list.add(t); + } + + Collections.sort(list, cmp); + return list; + } + + + public void render(OutputStream stream) throws Exception { + build().render(new XmlWriter(stream)); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/TextCoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/TextCoverageReport.java new file mode 100644 index 0000000..a85a41d --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/TextCoverageReport.java
@@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.reports; + +import java.io.BufferedWriter; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.coverage.ResourceCoverageInformation; + + +public class TextCoverageReport implements CoverageReport { + + private final LanguagePackCoverageReport coverage; + + public TextCoverageReport(LanguagePackCoverageReport coverage){ + this.coverage = coverage; + } + + public void render(OutputStream stream) throws Exception { + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream)); + + writer.write("Number of total plugins: " + coverage.getPluginCoverageReports().size()); //$NON-NLS-1$ + writer.newLine(); + + for (LocaleProxy locale: coverage.getMatchesPerLocale().keySet()) { + writer.write("Number of matched plugins for " + locale.getName() + ": " + + coverage.getMatchesPerLocale().get(locale)); //$NON-NLS-1$ $NON-NLS-2$ + writer.newLine(); + } + + for (PluginCoverageInformation pluginReport: coverage.getPluginCoverageReports()) { + writer.newLine(); + writer.write(pluginReport.getEclipseArchivePlugin().getName()); + writer.newLine(); + + for (LocaleProxy locale : pluginReport.getPluginMatchingPerLocale().keySet()) { + writer.write(locale.getName() + " -> " + pluginReport.getPluginMatchingPerLocale().get(locale)); + writer.newLine(); + } + + for (String resourcePath : pluginReport.getResourceCoverage().keySet()) { + ResourceCoverageInformation resourceCoverageInfo = pluginReport.getResourceCoverage().get(resourcePath); + writer.write(resourcePath); + writer.newLine(); + + for (LocaleProxy locale : resourceCoverageInfo.getRecordedLocales()) { + writer.write("Locale " + locale.getName() + ": " + resourceCoverageInfo.getMatchingForLocale(locale)); //$NON-NLS-1$ $NON-NLS-2$ + writer.newLine(); + writer.write("Locale property coverage " + locale.getName() + ": " + resourceCoverageInfo.getMatchedPercentageForLocale(locale)); //$NON-NLS-1$ $NON-NLS-2$ + writer.newLine(); + } + } + } + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/XmlCoverageReport.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/XmlCoverageReport.java new file mode 100644 index 0000000..9615296 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/reports/XmlCoverageReport.java
@@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/** + * + */ +package org.eclipse.babel.build.core.reports; + +import static org.eclipse.babel.build.core.xml.Builder.sequence; +import static org.eclipse.babel.build.core.xml.Coverage.archive; +import static org.eclipse.babel.build.core.xml.Coverage.coverage; +import static org.eclipse.babel.build.core.xml.Coverage.locale; +import static org.eclipse.babel.build.core.xml.Coverage.locales; +import static org.eclipse.babel.build.core.xml.Coverage.output; +import static org.eclipse.babel.build.core.xml.Coverage.plugin; +import static org.eclipse.babel.build.core.xml.Coverage.plugins; +import static org.eclipse.babel.build.core.xml.Coverage.resource; +import static org.eclipse.babel.build.core.xml.Coverage.translations; + +import java.io.OutputStream; +import java.util.Date; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.coverage.PluginCoverageInformation; +import org.eclipse.babel.build.core.xml.Element; +import org.eclipse.babel.build.core.xml.XmlWriter; +import org.eclipse.babel.build.core.xml.Builder.ToNode; + + +public class XmlCoverageReport implements CoverageReport{ + public class ResourceToNode implements ToNode<ResourceProxy> { + + private final PluginCoverageInformation info; + private final PluginProxy plugin; + + public ResourceToNode(PluginCoverageInformation info) { + this.info = info; + plugin = info.getEclipseArchivePlugin(); + } + + public Element toNode(final ResourceProxy resource) { + if(!config.includeResource(plugin, resource)){ + return resource(resource.getRelativePath(), true); + } + + return resource(resource.getRelativePath(), + sequence(config.locales(), new ToNode<LocaleProxy>(){ + public Element toNode(LocaleProxy locale) { + int score = CoverageReport.utils.calculateCoverageScore(locale, resource, info); + return locale(locale.getName(), score); + } + })); + } + } + + public static class LocaleToNode implements ToNode<LocaleProxy> { + public Element toNode(LocaleProxy locale) { + return locale(locale.getName()); + } + } + + private final Configuration config; + private final LanguagePackCoverageReport coverage; + + public XmlCoverageReport(Configuration config, LanguagePackCoverageReport coverage){ + this.config = config; + this.coverage = coverage; + } + + public Element build() { + return coverage(config.timestamp() == null ? new Date().toString() : config.timestamp().toString(), + archive(config.eclipseInstall().getLocation().getAbsolutePath()), + translations(config.translations().getRootDirectory().getAbsolutePath()), + output(config.workingDirectory().getAbsolutePath()), + locales(sequence(config.locales(), new LocaleToNode())), + plugins(sequence(coverage.getPluginCoverageReports(), new PluginToNode())) + ); + } + + private class PluginToNode implements ToNode<PluginCoverageInformation> { + + public Element toNode(PluginCoverageInformation info) { + PluginProxy plugin = info.getEclipseArchivePlugin(); + return plugin(plugin.getName(), plugin.getVersion(), + sequence(plugin.getResources(), new ResourceToNode(info)) + ); + } + + } + + public void render(OutputStream stream) throws Exception { + build().render(new XmlWriter(stream)); + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogue.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogue.java new file mode 100644 index 0000000..cc70d58 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogue.java
@@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.translationcatalogue; + +import java.io.File; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.babel.build.core.LocaleGroup; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; +import org.eclipse.babel.build.core.exceptions.MissingLocationException; + + +public class TranslationCatalogue { + + private File rootDirectory; + private Set<LocaleProxy> locales = new HashSet<LocaleProxy>(); + private Set<LocaleProxy> allLocales; + + private TranslationCatalogueParser catalogueParser; + + public TranslationCatalogue(File root, Collection<LocaleProxy> locales) + throws MissingLocationException, InvalidLocationException, InvalidFilenameException { + this.rootDirectory = root.getAbsoluteFile(); + + if (!this.rootDirectory.exists()) { + throw new MissingLocationException(); + } else if (!this.rootDirectory.isDirectory()) { + throw new InvalidFilenameException(); + } + + this.locales.addAll(locales); + this.allLocales = new HashSet<LocaleProxy>(); + + catalogueParser = new TranslationCatalogueSimpleParser(this.rootDirectory, this.locales); + this.allLocales = catalogueParser.findRelevantLocalesInCatalogue(); + if (this.locales.isEmpty()) { + this.locales = this.allLocales; + } + } + + public TranslationCatalogue(File root, Set<LocaleGroup> localeGroups) + throws MissingLocationException, InvalidLocationException, InvalidFilenameException { + this.rootDirectory = root.getAbsoluteFile(); + + if (!this.rootDirectory.exists()) { + throw new MissingLocationException(); + } else if (!this.rootDirectory.isDirectory()) { + throw new InvalidFilenameException(); + } + + this.allLocales = new HashSet<LocaleProxy>(); + + catalogueParser = new TranslationCatalogueBulkParser(this.rootDirectory, localeGroups); + this.allLocales = catalogueParser.findRelevantLocalesInCatalogue(); + this.locales = this.allLocales; + } + + /** + * @param eclipseInstallPlugin + * @return The different versions (one for each locale) of the same plug-in within the catalogue. + */ + public Map<String, PluginProxy> getPluginForSpecifiedLocales (PluginProxy eclipseInstallPlugin) { + return catalogueParser.getPluginForSpecifiedLocales(eclipseInstallPlugin); + } + + /** + * @param eclipseInstallFeature + * @return The different versions (one for each locale) of the same feature within the catalogue. + */ + public Map<String, PluginProxy> getFeatureForSpecifiedLocales (PluginProxy eclipseInstallFeature) { + return catalogueParser.getFeatureForSpecifiedLocales(eclipseInstallFeature); + } + + public ResourceProxy getResourceTranslation(PluginProxy translationCataloguePlugin, ResourceProxy eclipseInstallPluginResource) { + for (ResourceProxy candidateTranslatedResource: translationCataloguePlugin.getResources()) { + if (candidateTranslatedResource.getRelativePath(). + equalsIgnoreCase(eclipseInstallPluginResource.getRelativePath())) { + return candidateTranslatedResource; + } + } + return null; + } + + public Set<LocaleProxy> getAllLocales() { + return allLocales; + } + + public File getRootDirectory() { + return rootDirectory; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueBulkParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueBulkParser.java new file mode 100644 index 0000000..bd33492 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueBulkParser.java
@@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.translationcatalogue; + +import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.babel.build.core.LocaleGroup; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; + + +public class TranslationCatalogueBulkParser implements TranslationCatalogueParser { + + private File rootDirectory; + private Set<LocaleGroup> specifiedGroups; + + public TranslationCatalogueBulkParser(File rootDirectory, Set<LocaleGroup> specifiedGroups) { + this.rootDirectory = rootDirectory; + this.specifiedGroups = specifiedGroups; + } + + /** + * + * @param eclipseInstallPlugin + * @return The different versions (one for each locale) of the same plug-in within the catalogue. + */ + public Map<String, PluginProxy> getPluginForSpecifiedLocales (PluginProxy eclipseInstallPlugin) { + Map<String, PluginProxy> plugins = new HashMap<String, PluginProxy>(); + + for (File subDir: rootDirectory.listFiles()) { + if (LocaleGroup.isValidGroupName(subDir.getName()) && isIncludedGroup(subDir.getName())) { + + for (File localeDir: subDir.listFiles()) { + + String group = subDir.getName(); + + File pluginsRoot = new File(rootDirectory.getAbsolutePath() + + File.separatorChar + group + File.separatorChar + localeDir.getName() + + File.separatorChar + PLUGINS_PATH); + + File pluginFile = new File(pluginsRoot.getAbsolutePath() + File.separator + eclipseInstallPlugin.getName()); + + if(pluginFile.exists()) { + List<ResourceProxy> pluginResources = extractResources(pluginFile, pluginFile.getName()); + plugins.put(localeDir.getName(), new PluginProxy(pluginFile, pluginResources, false, false)); + } + } + } + } + + return plugins; + } + + /** + * + * @param eclipseInstallFeature + * @return The different versions (one for each locale) of the same feature within the catalogue. + */ + public Map<String, PluginProxy> getFeatureForSpecifiedLocales (PluginProxy eclipseInstallFeature) { + Map<String, PluginProxy> features = new HashMap<String, PluginProxy>(); + + for (File subDir: rootDirectory.listFiles()) { + if (LocaleGroup.isValidGroupName(subDir.getName()) && isIncludedGroup(subDir.getName())) { + + for (File localeDir: subDir.listFiles()) { + + String group = subDir.getName(); + + File featuresRoot = new File(rootDirectory.getAbsolutePath() + + File.separatorChar + group + File.separatorChar + localeDir.getName() + + File.separatorChar + FEATURES_PATH); + + File featureFile = new File(featuresRoot.getAbsolutePath() + File.separator + eclipseInstallFeature.getName()); + + if(featureFile.exists()) { + List<ResourceProxy> featureResources = extractResources(featureFile, featureFile.getName()); + features.put(localeDir.getName(), new PluginProxy(featureFile, featureResources, false, false)); + } + } + } + } + + return features; + } + + private List<ResourceProxy> extractResources(File file, String pluginName) { + List<ResourceProxy> resources = new LinkedList<ResourceProxy>(); + for (File subFile: file.listFiles()) { + if (subFile.isDirectory()) { + resources.addAll(extractResources(subFile, pluginName)); + } + else { + String absolutePath = subFile.getAbsolutePath(); + String relativePath = absolutePath.substring(absolutePath.indexOf(pluginName)); + relativePath = relativePath.substring(pluginName.length() + 1); + resources.add(new ResourceProxy(subFile, relativePath)); + } + } + return resources; + } + + private boolean isIncludedGroup(String name) { + return this.specifiedGroups.contains(LocaleGroup.GROUP_ALL) || this.specifiedGroups.contains(LocaleGroup.get(name)); + } + + /** + * Extract the list of all the relevant locales featured in the Translation Catalogue. + * The assumption is that all folders within relevant group folders are locales. + */ + public Set<LocaleProxy> findRelevantLocalesInCatalogue() throws InvalidLocationException { + Set<LocaleProxy> allLocales = new HashSet<LocaleProxy>(); + + for (File groupDir: rootDirectory.listFiles()) { + if (LocaleGroup.isValidGroupName(groupDir.getName()) && isIncludedGroup(groupDir.getName())) { + for (File localeDir: groupDir.listFiles()) { + allLocales.add(new LocaleProxy(localeDir.getName())); + } + } + } + + if (allLocales.isEmpty()) { + throw new InvalidLocationException( + Messages.getString("Error_invalid_translation_catalogue_bulk")); //$NON-NLS-1$ + } + + return allLocales; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueParser.java new file mode 100644 index 0000000..e73bfe9 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueParser.java
@@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.translationcatalogue; + +import java.util.Map; +import java.util.Set; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; + + +public interface TranslationCatalogueParser { + public final static String PLUGINS_PATH = Messages.getString("Paths_plugins_directory"); //$NON-NLS-1$ + public final static String FEATURES_PATH = Messages.getString("Paths_features_directory"); //$NON-NLS-1$ + + /** + * @param eclipseInstallPlugin + * @return The different versions (one for each locale) of the same plug-in within the catalogue. + */ + public Map<String, PluginProxy> getPluginForSpecifiedLocales (PluginProxy eclipseInstallPlugin); + + /** + * @param eclipseInstallFeature + * @return The different versions (one for each locale) of the same feature within the catalogue. + */ + public Map<String, PluginProxy> getFeatureForSpecifiedLocales (PluginProxy eclipseInstallFeature); + + /** + * Extract the list of all the relevant locales featured in the Translation Catalogue. + */ + public Set<LocaleProxy> findRelevantLocalesInCatalogue() throws InvalidLocationException; +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueSimpleParser.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueSimpleParser.java new file mode 100644 index 0000000..2d1914b --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/translationcatalogue/TranslationCatalogueSimpleParser.java
@@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.translationcatalogue; + +import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.Messages; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; + + +public class TranslationCatalogueSimpleParser implements + TranslationCatalogueParser { + + private File rootDirectory; + private Set<LocaleProxy> locales; + + public TranslationCatalogueSimpleParser(File rootDirectory, Set<LocaleProxy> locales) { + this.locales = locales; + this.rootDirectory = rootDirectory; + } + + /** + * + * @param eclipseInstallPlugin + * @return The different versions (one for each locale) of the same plug-in within the catalogue. + */ + public Map<String, PluginProxy> getPluginForSpecifiedLocales (PluginProxy eclipseInstallPlugin) { + Map<String, PluginProxy> plugins = new HashMap<String, PluginProxy>(); + + for (LocaleProxy locale : this.locales) { + PluginProxy plugin = getPluginForLocale(locale, eclipseInstallPlugin); + if (plugin != null) { + plugins.put(locale.getName(), plugin); + } + } + return plugins; + } + + /** + * + * @param eclipseInstallPlugin + * @return The different versions (one for each locale) of the same feature within the catalogue. + */ + public Map<String, PluginProxy> getFeatureForSpecifiedLocales (PluginProxy eclipseInstallFeature) { + Map<String, PluginProxy> features = new HashMap<String, PluginProxy>(); + + for (LocaleProxy locale : this.locales) { + PluginProxy feature = getFeatureForLocale(locale, eclipseInstallFeature); + if ( feature != null ) { + features.put( locale.getName(), feature ); + } + } + + return features; + } + + /** + * Assumes that the locale folder is directly under the translation catalogue's root folder. + * + * @param locale + * @param eclipseInstallPlugin + * @return The eclipseInstallPlugin's corresponding plug-in in the catalogue for the specified locale. + */ + private PluginProxy getPluginForLocale(LocaleProxy locale, PluginProxy eclipseInstallPlugin) { + + for (File localeDir: rootDirectory.listFiles()) { + if ( localeDir.getName().equalsIgnoreCase(locale.getName()) ) { + + File pluginsRoot = new File(rootDirectory.getAbsolutePath() + + File.separatorChar + localeDir.getName() + + File.separatorChar + PLUGINS_PATH); + + File pluginFile = new File(pluginsRoot.getAbsolutePath() + File.separator + eclipseInstallPlugin.getName()); + + if(pluginFile.exists()) { + List<ResourceProxy> pluginResources = extractResources(pluginFile, pluginFile.getName()); + return new PluginProxy(pluginFile, pluginResources, false, false); + } + } + } + + return null; + } + + /** + * Assumes that the locale folder is directly under the translation catalogue's root folder. + * + * @param locale + * @param eclipseInstallFeature + * @return The eclipseInstallFeature's corresponding plug-in in the catalogue for the specified locale. + */ + private PluginProxy getFeatureForLocale(LocaleProxy locale, PluginProxy eclipseInstallFeature) { + + for (File localeDir: rootDirectory.listFiles()) { + if ( localeDir.getName().equalsIgnoreCase(locale.getName()) ) { + + File featuresRoot = new File(rootDirectory.getAbsolutePath() + + File.separatorChar + localeDir.getName() + + File.separatorChar + FEATURES_PATH); + + File featureFile = new File(featuresRoot.getAbsolutePath() + File.separator + eclipseInstallFeature.getName()); + + if(featureFile.exists()) { + List<ResourceProxy> featureResources = extractResources(featureFile, featureFile.getName()); + return new PluginProxy(featureFile, featureResources, false, false); + } + } + } + + return null; + } + + public ResourceProxy getResourceTranslation(PluginProxy translationCataloguePlugin, ResourceProxy eclipseInstallPluginResource) { + for (ResourceProxy candidateTranslatedResource: translationCataloguePlugin.getResources()) { + if (candidateTranslatedResource.getRelativePath(). + equalsIgnoreCase(eclipseInstallPluginResource.getRelativePath())) { + return candidateTranslatedResource; + } + } + return null; + } + + private List<ResourceProxy> extractResources(File file, String pluginName) { + List<ResourceProxy> resources = new LinkedList<ResourceProxy>(); + for (File subFile: file.listFiles()) { + if (subFile.isDirectory()) { + resources.addAll(extractResources(subFile, pluginName)); + } + else { + String absolutePath = subFile.getAbsolutePath(); + String relativePath = absolutePath.substring(absolutePath.indexOf(pluginName)); + relativePath = relativePath.substring(pluginName.length() + 1); + resources.add(new ResourceProxy(subFile, relativePath)); + } + } + return resources; + } + + /** + * Extract the list of all the relevant locales featured in the Translation Catalogue. + * The assumption is that all folders within the catalogue's root folder are locales. + */ + public Set<LocaleProxy> findRelevantLocalesInCatalogue() throws InvalidLocationException { + Set<LocaleProxy> allLocales = new HashSet<LocaleProxy>(); + + for (File localeDir: rootDirectory.listFiles()) { + LocaleProxy candidateLocale = new LocaleProxy(localeDir.getName()); + /* If it's in the list of specified locales, or if the latter is empty (meaning all + locales are to be included), then the candidate is a relevant locale. */ + if (locales.contains(candidateLocale) || locales.isEmpty()) { + allLocales.add(candidateLocale); + } + } + + if (allLocales.isEmpty()) { + throw new InvalidLocationException(Messages.getString("Error_invalid_translation_catalogue")); //$NON-NLS-1$ + } else if (locales.isEmpty()) { + locales = allLocales; + } + + return allLocales; + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Attribute.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Attribute.java new file mode 100644 index 0000000..fc2c894 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Attribute.java
@@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +/** + * An attribute pair on an Element in a Builder document tree. + */ +public class Attribute { + private final String name; + private final String value; + + /** + * Create a new attribute. + * + * @param name The name of the attribute. + * @param value The value of the attribute. + */ + public Attribute(String name, String value){ + this.name = name; + this.value = value; + } + + /** + * Retrieve the attribute's name. + * + * @return The attribute's name. + */ + public String getName() { + return name; + } + + /** + * Retrieve the attribute's value. + * + * @return The attribute's value. + */ + public String getValue() { + return value; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Builder.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Builder.java new file mode 100644 index 0000000..a2f5306 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Builder.java
@@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * High level XML serialization tool modeled after the Ruby Builder API. + * Contains static methods that allow clients to easily build document trees. + * + * For example: + * + * <pre> + * Document doc = root("contacts", + * element("description", text("People that I know")), + * element("people", + * element("person").attribute("name", "Alice"), + * element("person").attribute("name", "Bob") + * ) + * ); + * + * doc.render(new XmlWriter(System.out)); + * </pre> + */ +public class Builder{ + private Builder(){} + + + public interface ToNode<T>{ + Element toNode(T t); + } + + public static <T> Element sequence(final Iterable<T> ts, final ToNode<T> toNode){ + return new Element.NodeIterator(){ + Iterator<T> iter = ts.iterator(); + + @Override + public Element next() { + try{ + T t = iter.next(); + return toNode.toNode(t); + } catch (NoSuchElementException ex){ + /* Reached the end of the iterable */ + return null; + } + } + }; + } + + public static Element nodes(Element... children){ + return new Element.NodeSequence(children); + } + + + /** + * Creates a new element. + * + * @param ns The namespace of the element. + * @param tag The local name of the element. + * @param elements The child elements of this element. + * @return The newly created element. + */ + public static Element element(String ns, String tag, Element... elements){ + return new TagElement(ns, tag, elements); + } + + /** + * Creates a new element in the default namespace. + * + * @param tag The local name of the element. + * @param elements The child elements of this element. + * @return The newly created element. + */ + public static Element element(String tag, Element... elements){ + return element("", tag, elements); + } + + /** + * Creates a new text node. + * @param text The text to be contained within the text node. + * @return The newly created text node. + */ + public static Element text(String text){ + return new TextElement(text); + } + + /** + * Creates a new document with a root element. + * + * @param ns The namespace of the root element. + * @param tag The local name of the root element. + * @param elements The children of the root element. + * @return The newly created document. + */ + public static Document root(String ns, String tag, Element...elements){ + return new Document(new TagElement(ns, tag, elements)); + } + + /** + * Creates a new document with a root element in the default namespace. + * + * @param tag The local name of the root element. + * @param elements The children of the root element. + * @return The newly create document. + */ + public static Document root(String tag, Element... elements){ + return root("", tag, elements); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Coverage.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Coverage.java new file mode 100644 index 0000000..e7b8753 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Coverage.java
@@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import static org.eclipse.babel.build.core.xml.Builder.*; + +/** + * Implements grammar specific builder elements to aid in the construction of coverage reports. + * For example: + * + * <pre> + * Document report = root("coverage", + * element("locales", + * locale("en"), + * locale("zh_TW"), + * ... + * ) + * ); + * + * report.render(new XmlWriter(System.out)); + * </pre> + */ +public class Coverage { + + public static Element coverage(String timestamp, Element... children){ + return root("coverage", children).attribute("timestamp", timestamp); + } + + public static Element archive(String location){ + return element("archive").attribute("location", location); + } + + public static Element translations(String location){ + return element("translations").attribute("location", location); + } + + public static Element output(String location){ + return element("output").attribute("location", location); + } + + /** + * Creates a coverage report resource element. + * + * @param location The location of the resource relative to the root of the eclipse archive. + * @param locales The locales into which the resource was localized. + * @return The resource element. + */ + public static Element resource(String location, Element... locales){ + return resource(location, false, locales); + } + + /** + * Creates a coverage report resource element. + * + * @param location The location of the resource element relative to the root of the eclipse archive. + * @param excluded Whether or not the resource was excluded from the coverage report. + * @param locales The locales into which the resource was localized. + * @return The resource element. + */ + public static Element resource(String location, boolean excluded, Element... locales){ + return element("resource", locales).attribute("location", location + ).attribute("excluded", (excluded ? "true" : "false")); + } + + /** + * Creates a coverage report locale element, representing a target locale. + * + * @param name The name of the locale. + * @param coverage The percentage of the resources that were translated into this locale. + * @return The locale element. + */ + public static Element locale(String name, int coverage){ + return locale(name).attribute("coverage", "" + coverage); + } + + /** + * Creates a coverage report locale element. + * + * @param name The name of the locale. + * @return The locale element. + */ + public static Element locale(String name){ + return element("locale").attribute("name", name); + } + + public static Element locales(Element... children){ + return element("locales", children); + } + + /** + * Creates a coverage report plugin element. + * + * @param name The name of the plugin (eg. "org.eclipse.core") + * @param version The version of the plugin that was translated (eg. 3.5.0) + * @param resources The resources in the plugin that were translated. + * @return The pluin element. + */ + public static Element plugin(String name, String version, Element... resources){ + return element("plugin", resources).attribute("name", name).attribute("version", version); + } + + public static Element plugins(Element... plugins){ + return element("plugins", plugins); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Document.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Document.java new file mode 100644 index 0000000..58e9604 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Document.java
@@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * Implements a Builder document element. + */ +public class Document implements Element { + private final Element root; + + + public Document(Element root) { + this.root = root; + } + + public void render(ContentHandler handler) throws SAXException { + handler.startDocument(); + root.render(handler); + handler.endDocument(); + } + + public Element attribute(String name, String value) { + root.attribute(name, value); + return this; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Element.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Element.java new file mode 100644 index 0000000..97f7036 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Element.java
@@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * Represents an element node in an XML document. + */ +public interface Element { + /** + * Implements an iterator over a sequence of nodes. + */ + public class NodeIterator implements Element { + public Element attribute(String name, String value) { + throw new UnsupportedOperationException("NodeIterators do not have attributes"); + } + + public void render(ContentHandler handler) throws SAXException { + Element element; + while((element = next()) != null){ + element.render(handler); + } + } + + public Element next(){ + return null; + } + + } + + public static class utils{ + + /** + * The empty element. Useful when building templates. + */ + public static final Element EMPTY_ELEMENT = new Element(){ + public Element attribute(String name, String value) { + return this; + } + + public void render(ContentHandler handler) throws SAXException {} + }; + } + + /** + * Implements a sequence of Elements. + */ + public static class NodeSequence implements Element{ + + private final Element[] children; + + public NodeSequence(Element... children){ + this.children = children; + } + + /** + * This method throws an UnsupportedOperationException as NodeSequences do not have attributes. + */ + public Element attribute(String name, String value) { + throw new UnsupportedOperationException("NodeSequences do not have attributes."); + } + + public void render(ContentHandler handler) throws SAXException { + for(Element child : children){ + child.render(handler); + } + } + + } + + /** + * Recursively render this element and it's children to the provided ContentHandler. + * + * @param handler The handler to send the SAX events describing this element and it's children. + * @throws SAXException + */ + public void render(ContentHandler handler) throws SAXException; + + /** + * Add an attribute to this element. + * May throw an UnsupportedOperationException if the underlying implementation does not have attributes. + * + * @param name The name of the attribute to create. + * @param value The value of the created attribute. + * @return This element. Allows chained calls to attribute. + */ + public Element attribute(String name, String value); +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Html.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Html.java new file mode 100644 index 0000000..b55d708 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Html.java
@@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import static org.eclipse.babel.build.core.xml.Builder.*; + +/** + * Implements grammar specific Builder elements to facilitate the generation of HTML documents. + */ +public class Html { + public static final String NS = "http://http://www.w3.org/1999/xhtml"; + + /** + * Creates a new HTML document. + * + * @param children The children of the root element. + * @return The newly created HTML document. + */ + public static Document html(Element... children){ + return (Document)root(NS, "html", children).attribute("xmlns", NS); + } + + /** + * Creates an HTML head element. + * + * @param children The children of the document's head. + * @return The newly create head element. + */ + public static Element head(Element... children){ + return element(NS, "head", children); + } + + /** + * Create an HTML title element. + * + * @param title The title of the document. + * @return The newly created title element. + */ + public static Element title(String title){ + return element(NS, "title", text(title)); + } + + /** + * Creates an HTML link element for linking to an external CSS stylesheet. + * + * @param url The URL of the stylesheet. + * @return The newly created link element. + */ + public static Element stylesheet(String url){ + return element(NS, "link") + .attribute("type", "text/css") + .attribute("href", url) + .attribute("rel", "stylesheet"); + + } + + public static Element style(String style){ + return element(NS, "style", text(style)).attribute("type", "text/css"); + } + + /** + * Create an HTML body element. + * + * @param elements The children of the document's body. + * @return The newly created body element. + */ + public static Element body(Element...elements){ + return element(NS, "body", elements); + } + + /** + * Creates an HTML h1 element. + * + * @param title The title to be contained within the h1. + * @return The newly created h1 element. + */ + public static Element h1(String title){ + return h1(text(title)); + } + + public static Element h1(Element... children){ + return element(NS, "h1", children); + } + + /** + * Creates an HTML h2 element. + * + * @param title The title to be contained within the h2. + * @return The newly created h2 element. + */ + public static Element h2(String title){ + return element(NS, "h2", text(title)); + } + + public static Element h2(Element... children){ + return element(NS, "h2", children); + } + + /** + * Creates an HTML table element. + * + * @param children The children of the table element. + * @return The table. + */ + public static Element table(Element... children){ + return element(NS, "table", children); + } + + /** + * Creates an HTML table row (tr) element. + * + * @param children The children of the tr. + * @return The tr. + */ + public static Element tr(Element... children){ + return element(NS, "tr", children); + } + + /** + * Creates an HTML table data cell (td) element. + * + * @param children The children of the td. + * @return The td. + */ + public static Element td(Element... children){ + return element(NS, "td", children); + } + + /** + * Creates an HTML table data cell (td) element. + * + * @param text The text to be contained within the td. + * @return The td. + */ + public static Element td(String text){ + return td(text(text)); + } + + /** + * Creates an HTML table header cell (th) element. + * + * @param title The text to be contained within the th. + * @return The th. + */ + public static Element th(String title){ + return element(NS, "th", text(title)); + } + + + /** + * Creates an HTML anchor element for linking to another hypertext document. + * + * @param href The url to link to. + * @param children The children of the a. + * @return The a. + */ + public static Element a(String href, Element... children){ + return element(NS, "a", children).attribute("href", href); + } + + /** + * Creates an HTML anchor element for linking to another hypertext document. + * + * @param href The url to link to. + * @param description The descriptive text to use with the link. + * @return The a. + */ + public static Element a(String href, String description){ + return a(href, text(description)); + } + + /** + * Creates an HTML unordered list (ul) element. + * + * @param children The children of the ul. + * @return The ul. + */ + public static Element ul(Element... children){ + return element(NS, "ul", children); + } + + /** + * Creates an HTML list item (li) element. + * + * @param text The text contained within the li. + * @return The li. + */ + public static Element li(String text){ + return element(NS, "li", text(text)); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/SavedConfiguration.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/SavedConfiguration.java new file mode 100644 index 0000000..4a58a49 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/SavedConfiguration.java
@@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import java.io.File; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.Filter; +import org.eclipse.babel.build.core.LocaleGroup; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.Range; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + + +public class SavedConfiguration implements Configuration { + + public EclipseTarget eclipseInstall() { + // TODO Auto-generated method stub + return null; + } + + public Range compatibilityRange() { + // TODO Auto-generated method stub + return null; + } + + public List<Filter> filters() { + // TODO Auto-generated method stub + return null; + } + + public boolean includePseudoTranslations() { + // TODO Auto-generated method stub + return false; + } + + public boolean includeResource(PluginProxy plugin, ResourceProxy resouce) { + // TODO Auto-generated method stub + return false; + } + + public File reportLocation() { + // TODO Auto-generated method stub + return null; + } + + public Date timestamp() { + // TODO Auto-generated method stub + return null; + } + + public TranslationCatalogue translations() { + // TODO Auto-generated method stub + return null; + } + + public File workingDirectory() { + // TODO Auto-generated method stub + return null; + } + + public Set<LocaleProxy> locales() { + // TODO Auto-generated method stub + return null; + } + + public Set<LocaleGroup> localeGroups() { + // TODO Auto-generated method stub + return null; + } + + public Set<String> excludeList() { + // TODO Auto-generated method stub + return null; + } + + public void notifyProgress(String fragmentName) { + // TODO Auto-generated method stub + } + + public boolean includeXmlReport() { + // TODO Auto-generated method stub + return false; + } + + public boolean longReport() { + // TODO Auto-generated method stub + return false; + } + + public String localeExtension() { + // TODO Auto-generated method stub + return null; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Schemas.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Schemas.java new file mode 100644 index 0000000..1a0099e --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/Schemas.java
@@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import javax.xml.XMLConstants; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.xml.sax.SAXException; + +/** + * Loads an parses the XMLSchemas used to define the format of the coverage reports and saved configurations. + */ +public class Schemas { + + /** + * The schema which defines the format of the XML coverage reports. + */ + public static final Schema COVERAGE = loadSchema("/azure/build/core/xml/coverage.xsd"); + + /** + * The schema which defines the format of saved build configurations. + */ + public static final Schema CONFIG = loadSchema("/azure/build/core/xml/config.xsd"); + + private static Schema loadSchema(String schema) { + try { + return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI + ).newSchema(Schema.class.getResource(schema)); + } catch (SAXException e) { + throw new AssertionError("Cannot load schema: (" + schema + ")"); + } finally { + if(schema == null){ + throw new AssertionError("Cannot load schema: (" + schema + ")"); + } + } + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TagElement.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TagElement.java new file mode 100644 index 0000000..d08d086 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TagElement.java
@@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import java.util.LinkedList; +import java.util.List; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Implements a builder Element node. + */ +public class TagElement implements Element { + private final String tag; + private final AttributesImpl attrs = new AttributesImpl(); + private final List<Element> children = new LinkedList<Element>(); + private final String namespace; + + public TagElement(String namespace, String tag, Element... children){ + this.namespace = namespace; + this.tag = tag; + + for(Element element : children){ + this.children.add(element); + } + } + + public void render(ContentHandler handler) throws SAXException { + handler.startElement(namespace, tag, null, attrs); + for(Element child : children){ + child.render(handler); + } + handler.endElement(namespace, tag, null); + } + + public Element attribute(String name, String value) { + attrs.addAttribute(null, null, name, "string", value); + return this; + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TextElement.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TextElement.java new file mode 100644 index 0000000..4b0fb9d --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/TextElement.java
@@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +/** + * Implements a Builder text node. + */ +public class TextElement implements Element{ + private final String text; + + public TextElement(String text){ + this.text = text; + } + + public void render(ContentHandler handler) throws SAXException { + char[] ch = text.toCharArray(); + handler.characters(ch, 0, ch.length); + } + + public Element attribute(String name, String value) { + throw new UnsupportedOperationException(); + } +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/XmlWriter.java b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/XmlWriter.java new file mode 100644 index 0000000..829eb6b --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/XmlWriter.java
@@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.core.xml; + +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + +/** + * A content handler which serialises SAX events to a stream. + * Useful for serialising XML documents. + * + * For a higher level XML serialisation library {@link org.eclipse.babel.build.core.xml.Builder} + */ +public class XmlWriter implements ContentHandler { + + private final PrintWriter out; + + public XmlWriter(PrintWriter out){ + this.out = out; + } + + public XmlWriter(Writer out){ + this(new PrintWriter(out)); + } + + + public XmlWriter(OutputStream out) { + this(new OutputStreamWriter(out)); + } + + public void characters(char[] ch, int start, int length) throws SAXException { + out.write(ch, start, length); + } + + public void endDocument() throws SAXException { + out.flush(); + } + + public void endElement(String uri, String localName, String name) throws SAXException { + out.format("</%s>\n", localName); + } + + public void endPrefixMapping(String prefix) throws SAXException { + throw new UnsupportedOperationException(); + } + + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + throw new UnsupportedOperationException(); + } + + public void processingInstruction(String target, String data) throws SAXException { + throw new UnsupportedOperationException(); + } + + public void setDocumentLocator(Locator locator) { + throw new UnsupportedOperationException(); + } + + public void skippedEntity(String name) throws SAXException { + throw new UnsupportedOperationException(); + } + + public void startDocument() throws SAXException { + out.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + } + + public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { + List<String> attrs = new LinkedList<String>(); + int len = atts.getLength(); + + if(len > 0){ + attrs.add(""); + } + for(int i = 0; i < len; i++){ + attrs.add(String.format("%s=\"%s\"", atts.getQName(i), atts.getValue(i))); + } + + out.format("<%s%s>", localName, join(" ", attrs)); + } + + private <T> String join(String seperator, Iterable<T> parts){ + StringBuilder builder = new StringBuilder(""); + for(Iterator<T> it = parts.iterator(); it.hasNext();){ + T part = it.next(); + + builder.append(part.toString()); + if(it.hasNext()){ + builder.append(seperator); + } + } + + return builder.toString(); + } + + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + throw new UnsupportedOperationException(); + } + +}
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/config.xsd b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/config.xsd new file mode 100644 index 0000000..f254398 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/config.xsd
@@ -0,0 +1,112 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:annotation> + <xs:documentation xml:lang="en"> + Configuration file schema for NL catalogue generator. + Copyright 2008 IBM. All rights reserved. + </xs:documentation> + </xs:annotation> + + <!-- + config is the root element of a configuration file. + mode: either 'production' or 'testing' + compatibilityRange: range of plug-in versions that generated fragments are + compatible with. + includePseudoTranslation: whether or not the generated fragments should + contain pseudo translation of messages. + + archive is the eclipse archive used to generate the translation catalogue + location: the path to the archive + translations is the translations used to generate the translations catalogue + location: the path to the translations + workspace is where the generator stores the output produced + location: the path to the generated output + timestamp + value: is the timestamp to use in generated artifacts, YY-MM-DDThh:mm:ss + format: the format the timestamp should take in generated artifacts + + report values associated with the report + location: location at which the report should be saved + + include a resource that should be included in the report + file: pattern to specify resources by filename + exclude a resource that should be excluded from the report + file: pattern to specify resources by filename + --> + + <xs:element name="config"> + <xs:complexType> + <xs:all> + <xs:element type="location" name="archive" /> + <xs:element type="location" name="translations" /> + <xs:element maxOccurs="1" name="timestamp" minOccurs="0"> + <xs:complexType> + <xs:attribute type="dateTime" default="now" name="value" /> + <xs:attribute type="xs:string" default="%y-%M-%d" name="format" /> + </xs:complexType> + </xs:element> + <xs:element type="location" name="workspace" /> + <xs:element maxOccurs="1" name="report" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element type="filter" name="include" /> + <xs:element type="filter" name="exclude" /> + </xs:choice> + </xs:sequence> + <xs:attribute type="path" name="location" /> + </xs:complexType> + </xs:element> + </xs:all> + <xs:attribute type="xs:string" name="compatibilityRange" /> + <xs:attribute type="mode" default="production" name="mode" /> + <xs:attribute type="boolean" default="false" name="includePseudoTranslation" /> + </xs:complexType> + </xs:element> + + <!-- A date and time specifier, allows the special value 'now' --> + <xs:simpleType name="dateTime"> + <xs:union memberTypes="xs:dateTime now" /> + </xs:simpleType> + + <xs:simpleType name="now"> + <xs:restriction base="xs:string"> + <xs:enumeration value="now" /> + </xs:restriction> + </xs:simpleType> + + <xs:complexType name="location"> + <xs:attribute type="path" name="location" /> + </xs:complexType> + + <xs:complexType name="filter"> + <xs:attribute type="xs:string" name="file" /> + </xs:complexType> + + <!-- A boolean, either 'true' or 'false' --> + <xs:simpleType name="boolean"> + <xs:restriction base="xs:string"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + + <!-- + A path: a number of path elements delimited by '/'. + '\' is not allowed in a path. + --> + <xs:simpleType name="path"> + <xs:restriction base="xs:string"> + <xs:pattern value="[^/\\]*(/[^/\\]{1,})*" /> + </xs:restriction> + </xs:simpleType> + + <!-- A mode, either 'testing' or 'production' --> + <xs:simpleType name="mode"> + <xs:restriction base="xs:string"> + <xs:enumeration value="testing" /> + <xs:enumeration value="production" /> + </xs:restriction> + </xs:simpleType> +</xs:schema>
diff --git a/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/coverage.xsd b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/coverage.xsd new file mode 100644 index 0000000..a295058 --- /dev/null +++ b/org.eclipse.babel.build.core/src/org/eclipse/babel/build/core/xml/coverage.xsd
@@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:annotation> + <xs:documentation xml:lang="en"> + Coverage report file schema for NL cataglogue generator. + Copyright 2008 IBM. All rights reserved. + </xs:documentation> + </xs:annotation> + + <!-- + coverage is the root element of a coverage report + timestamp: is the time at which the report was generated in the format + YY-MM-DDThh:mm:ss + + archive is the eclipse archive used to generate the translation catalogue + location: the path to the archive + translations is the translations used to generate the translations catalogue + location: the path to the translations + output is the output produced by the generator + location: the path to the generated output + locales is an enumeration of the locales processed during generation + plugins is an enumeration of the plug-ins processed during generation + --> + <xs:element name="coverage"> + <xs:complexType> + <xs:all> + <xs:element type="location" name="archive" /> + <xs:element type="location" name="translations" /> + <xs:element type="location" name="output" /> + <xs:element name="locales" type="locales" /> + <xs:element name="plugins" type="plugins" /> + </xs:all> + <xs:attribute name="timestamp" type="xs:dateTime" /> + </xs:complexType> + </xs:element> + + <!-- + locale is an element specifying a single locale + name: the name of a locale (eg. 'en', 'zh_TW', etc.) + --> + <xs:complexType name="locales"> + <xs:sequence> + <xs:element name="locale" minOccurs="1" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="name" type="xs:string" /> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + + <!-- an enumeration of one or more plug-ins --> + <xs:complexType name="plugins"> + <xs:sequence> + <xs:element name="plugin" type="plugin" minOccurs="1" maxOccurs="unbounded" /> + </xs:sequence> + </xs:complexType> + + <!-- + a plug-in in the eclipse archive + name: the name of the plug-in (eg. org.eclipse.core) + version: the version of the plug-in (eg. 1.5.0) + + resource is a resource in the plug-in + location: the path to the resource from the root of the plug-in + excluded: whether this resource was excluded from the generation + + locale the translation coverage in the context of this resource + name: name of the locale (eg. en, zh_TW, etc.) + coverage: percentage coverage of translations for this resource (eg. 75) + --> + <xs:complexType name="plugin"> + <xs:sequence> + <xs:element name="resource" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:sequence> + <xs:element name="locale" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="name" type="xs:string" /> + <xs:attribute name="coverage" type="xs:integer" /> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="location" type="path" /> + <xs:attribute name="excluded" type="boolean" default="false" /> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="name" type="xs:string" /> + <xs:attribute name="version" type="version" /> + </xs:complexType> + + <xs:complexType name="location"> + <xs:attribute type="path" name="location" /> + </xs:complexType> + + <xs:complexType name="filter"> + <xs:attribute type="xs:string" name="file" /> + </xs:complexType> + + <!-- A boolean: either 'true' or 'false' --> + <xs:simpleType name="boolean"> + <xs:restriction base="xs:string"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + + <!-- + A path: a number of path elements delimited by '/'. + '\' is not allowed in a path. + --> + <xs:simpleType name="path"> + <xs:restriction base="xs:string"> + <xs:pattern value="[^/\\]*(/[^/\\]{1,})*" /> + </xs:restriction> + </xs:simpleType> + + <!-- A version designation: a ',' delimited three tuple of digits. --> + <xs:simpleType name="version"> + <xs:restriction base="xs:string"> + <xs:pattern value="\d{1,}\.\d{1,}\.\d{1,}" /> + </xs:restriction> + </xs:simpleType> +</xs:schema>
diff --git a/org.eclipse.babel.build.ui/.classpath b/org.eclipse.babel.build.ui/.classpath new file mode 100644 index 0000000..64c5e31 --- /dev/null +++ b/org.eclipse.babel.build.ui/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/org.eclipse.babel.build.ui/.project b/org.eclipse.babel.build.ui/.project new file mode 100644 index 0000000..a36c394 --- /dev/null +++ b/org.eclipse.babel.build.ui/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.babel.build.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/org.eclipse.babel.build.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.babel.build.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b93f310 --- /dev/null +++ b/org.eclipse.babel.build.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@ +#Wed Nov 26 14:38:59 EST 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.babel.build.ui/META-INF/MANIFEST.MF b/org.eclipse.babel.build.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8d45052 --- /dev/null +++ b/org.eclipse.babel.build.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Babel Build UI +Bundle-SymbolicName: org.eclipse.babel.build.ui;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.babel.build.ui.Activator +Bundle-Vendor: Eclipse.org +Require-Bundle: org.eclipse.ui;bundle-version="[3.3.0,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.3.0,4.0.0)", + org.eclipse.pde.core;bundle-version="[3.3.0,4.0.0)", + org.eclipse.pde.ui;bundle-version="[3.3.0,4.0.0)", + org.eclipse.jdt.core;bundle-version="[3.3.0,4.0.0)", + org.eclipse.babel.build.core +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: ., + BuildCore.jar +Bundle-Localization: plugin +Main-Class: org.eclipse.babel.build.core.Main
diff --git a/org.eclipse.babel.build.ui/build.properties b/org.eclipse.babel.build.ui/build.properties new file mode 100644 index 0000000..ec58ed5 --- /dev/null +++ b/org.eclipse.babel.build.ui/build.properties
@@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + plugin.properties
diff --git a/org.eclipse.babel.build.ui/build_jardeps.xml b/org.eclipse.babel.build.ui/build_jardeps.xml new file mode 100644 index 0000000..e52e2ca --- /dev/null +++ b/org.eclipse.babel.build.ui/build_jardeps.xml
@@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project default="jar-deps" name="Babel Build"> + <property name="dir.ant" value="../org.eclipse.babel.build.ant" /> + + <target name="plugin_export"> + <pde.exportPlugins destination="/Users/aaron/Desktop/3.4_Final/workspace/azure.build.ui/dist" exportSource="false" exportType="directory" plugins="org.eclipse.babel.build.ui" useJARFormat="true"/> + </target> + + <target name="deps"> + <subant buildpath="${dir.ant}/build.xml" target="dist" /> + </target> + + <target name="jar-deps" depends="deps"> + <description>Build Babel Build jar containting command-line interface, ant task and plug-in</description> + <mkdir dir="build" /> + <unjar src="${dir.ant}/dist/azure-ant-deps.jar" dest="build" /> + <unjar src="dist/plugins/org.eclipse.babel.build.ui_1.0.0.jar" dest="build" /> + <delete file="dist/org.eclipse.babel.build_1.0.0.jar" /> + <zip basedir="build" file="dist/org.eclipse.babel.build_1.0.0.jar" /> + </target> +</project>
diff --git a/org.eclipse.babel.build.ui/icons/locale.gif b/org.eclipse.babel.build.ui/icons/locale.gif new file mode 100644 index 0000000..ec6cca4 --- /dev/null +++ b/org.eclipse.babel.build.ui/icons/locale.gif Binary files differ
diff --git a/org.eclipse.babel.build.ui/icons/plugin.gif b/org.eclipse.babel.build.ui/icons/plugin.gif new file mode 100644 index 0000000..8493df4 --- /dev/null +++ b/org.eclipse.babel.build.ui/icons/plugin.gif Binary files differ
diff --git a/org.eclipse.babel.build.ui/plugin.properties b/org.eclipse.babel.build.ui/plugin.properties new file mode 100644 index 0000000..d54237b --- /dev/null +++ b/org.eclipse.babel.build.ui/plugin.properties
@@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +#Properties file for org.eclipse.babel.build.ui +Bundle-Vendor.0 = Team Azure +Bundle-Name.0 = org.eclipse.babel.build.ui Plug-in +wizard.name.0 = Language Pack +wizard.description.0 = Generate a language pack for Eclipse plug-ins in a set of specified locales. +category.name.0 = Plug-in Globalization \ No newline at end of file
diff --git a/org.eclipse.babel.build.ui/plugin.xml b/org.eclipse.babel.build.ui/plugin.xml new file mode 100644 index 0000000..45c67ac --- /dev/null +++ b/org.eclipse.babel.build.ui/plugin.xml
@@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension point="org.eclipse.ui.exportWizards"> + <wizard + category="org.eclipse.babel.build.ui.Globalization" + class="org.eclipse.babel.build.ui.wizard.BuildToolWizard" + icon="icons/locale.gif" + id="org.eclipse.babel.build.ui.wizard.buildToolWizard" + name="%wizard.name.0"> + <description> + %wizard.description.0 + </description> + </wizard> + <category + id="org.eclipse.babel.build.ui.Globalization" + name="%category.name.0"> + </category> + </extension> +</plugin>
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/Activator.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/Activator.java new file mode 100644 index 0000000..a8f83b5 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/Activator.java
@@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.babel.build.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/handlers/SampleHandler.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/handlers/SampleHandler.java new file mode 100644 index 0000000..e1ffdfe --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/handlers/SampleHandler.java
@@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +public class SampleHandler extends AbstractHandler { + + public SampleHandler() { + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + return null; + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildInitializationOperation.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildInitializationOperation.java new file mode 100644 index 0000000..0fc2651 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildInitializationOperation.java
@@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; + +public class BuildInitializationOperation implements IRunnableWithProgress{ + private BuildToolModelTable fModelPluginsTable; + private BuildToolModelTable fModelLocalesTable; + private BuildToolModelTable fModelIgnoreTable; + private BuildToolModelTable fModelResourceExclusionTable; + + private ISelection fPluginSelection; + private List<String> fSelectedLocales = null; + private ArrayList<IProject> fSelectedPlugins; + private boolean fCanceled; + + public BuildInitializationOperation(ISelection pluginSelection, String[] localeSelection) { + fPluginSelection = pluginSelection; + if (localeSelection != null) { + fSelectedLocales = Arrays.asList(localeSelection); + } + } + + public void run(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + this.fillLocalesTable(); + this.fillPluginsTable(); + this.fillIgnoreTable(); + this.fillResourceExclusionTable(); + } + + private void fillPluginsTable() { + if (fPluginSelection instanceof IStructuredSelection) { + IPath MANIFEST_PATH = new Path("META-INF/MANIFEST.MF"); //$NON-NLS-1$ + IPath PLUGIN_PATH = new Path("plugin.xml"); //$NON-NLS-1$ + IPath FRAGMENT_PATH = new Path("fragment.xml"); //$NON-NLS-1$ + + Object[] plugins = ((IStructuredSelection) fPluginSelection).toArray(); + + fSelectedPlugins = new ArrayList<IProject>(plugins.length); + for (int i = 0; i < plugins.length; i++) { + //Handle plug-ins java projects (These are also plug-ins + if(plugins[i] instanceof IJavaProject) { + plugins[i] = ((IJavaProject)(((IStructuredSelection) fPluginSelection).toArray()[i])).getProject(); + } + //If a file was selected, get its parent project + if (plugins[i] instanceof IFile) + plugins[i] = ((IFile) plugins[i]).getProject(); + + //Add the project to the preselected model list + if (plugins[i] instanceof IProject + && (((IProject)plugins[i]).exists(MANIFEST_PATH) + || ((IProject)plugins[i]).exists(PLUGIN_PATH) + || ((IProject)plugins[i]).exists(FRAGMENT_PATH))) { + fSelectedPlugins.add((IProject)plugins[i]); + } + } + } + //Get all models (workspace and external) excluding fragment models + IPluginModelBase[] pluginModels = PluginRegistry.getAllModels(false); + + //Populate list to an InternationalizeModelTable + fModelPluginsTable = new BuildToolModelTable(); + for (int i = 0; i < pluginModels.length; i++) { + fModelPluginsTable.addToModelTable(pluginModels[i], pluginModels[i].getUnderlyingResource() != null ? isPluginSelected(pluginModels[i].getUnderlyingResource().getProject()) : false); + } + } + + private void fillLocalesTable() { + fModelLocalesTable = new BuildToolModelTable(); + Locale[] availableLocales = Locale.getAvailableLocales(); + for (int i = 0; i < availableLocales.length; i++) { + fModelLocalesTable.addToModelTable(availableLocales[i], availableLocales != null ? isLocaleSelected(availableLocales[i].toString()) : false); + } + } + + private void fillIgnoreTable() { + fModelIgnoreTable = new BuildToolModelTable(); + } + + private void fillResourceExclusionTable() { + fModelResourceExclusionTable = new BuildToolModelTable(); + } + + /** + * + * @return whether or not the operation was canceled + */ + public boolean wasCanceled() { + return fCanceled; + } + + /** + * + * @param project + * @return whether or not the project was preselected + */ + public boolean isPluginSelected(IProject project) { + return fSelectedPlugins.contains(project); + } + + public boolean isLocaleSelected(String locale) { + if (fSelectedLocales == null) { + return false; + } + + return fSelectedLocales.contains(locale); + } + + /** + * + * @return the BuildToolModelTable containing the plug-ins + */ + public BuildToolModelTable getPluginsTable() { + return fModelPluginsTable; + } + + /** + * + * @return the BuildToolModelTable containing the locales + */ + public BuildToolModelTable getLocalesTable() { + return fModelLocalesTable; + } + + /** + * + * @return the BuildToolModelTable containing the ignore list + */ + public BuildToolModelTable getIgnoreTable() { + return fModelIgnoreTable; + } + + /** + * + * @return the BuildToolModelTable containing the resource exclusion list + */ + public BuildToolModelTable getResourceExclusionTable() { + return fModelResourceExclusionTable; + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolImages.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolImages.java new file mode 100644 index 0000000..f3e1e53 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolImages.java
@@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.net.URL; + +import org.eclipse.babel.build.ui.Activator; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; + + +public class BuildToolImages { + public final static String ICONS_PATH = "icons/"; //$NON-NLS-1$ + + public static final ImageDescriptor PLUGIN = create(ICONS_PATH, "plugin.gif"); //$NON-NLS-1$ + public static final ImageDescriptor LOCALE = create(ICONS_PATH, "locale.gif"); //$NON-NLS-1$ + + private static ImageDescriptor create(String prefix, String name) { + return ImageDescriptor.createFromURL(makeImageURL(prefix, name)); + } + + private static URL makeImageURL(String prefix, String name) { + String path = "$nl$/" + prefix + name; //$NON-NLS-1$ + return FileLocator.find(Activator.getDefault().getBundle(), new Path(path), null); + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolModelTable.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolModelTable.java new file mode 100644 index 0000000..11f0c49 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolModelTable.java
@@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.ArrayList; +import java.util.List; + +public class BuildToolModelTable { + private List<Object> fAvailableModels; + private List<Object> fPreSelectedModels; + + public BuildToolModelTable() { + fAvailableModels = new ArrayList<Object>(); + fPreSelectedModels = new ArrayList<Object>(); + } + + /** + * Adds the model to the model table. Takes into consideration the specified + * selection. + * @param model + * @param selected + */ + public void addToModelTable(Object model, boolean selected) { + if (selected) + fPreSelectedModels.add(model); + else + fAvailableModels.add(model); + } + + /** + * Adds the model to the model table. + * @param model + */ + public void addModel(Object model) { + fAvailableModels.add(model); + } + + /** + * Removes the specified model from the model table. + * @param model + */ + public void removeModel(Object model) { + fAvailableModels.remove(model); + } + + public void addToPreselected(Object model) { + fPreSelectedModels.add(model); + } + + public void removeFromPreselected(Object model) { + fPreSelectedModels.remove(model); + } + + /** + * + * @return the number of models in the table + */ + public int getModelCount() { + return fPreSelectedModels.size() + fAvailableModels.size(); + } + + /** + * Returns the list of models stored in the model table + * @return the array of models + */ + public Object[] getModels() { + return fAvailableModels.toArray(); + } + + /** + * Returns the list of preselected models stored in the model table + * @return the array of preselected models + */ + public Object[] getPreSelected() { + return fPreSelectedModels.toArray(); + } + + /** + * + * @return whether or not the model table contains preselected models + */ + public boolean hasPreSelected() { + return fPreSelectedModels.size() > 0; + } + + /** + * + * @return whether or not the list of models is empty + */ + public boolean isEmpty() { + return fAvailableModels.size() == 0; + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizard.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizard.java new file mode 100644 index 0000000..244e7c6 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizard.java
@@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.babel.build.ui.Activator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IExportWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + + +public class BuildToolWizard extends Wizard + implements IExportWizard { + + private final static String SELECTED_LOCALES = "BuildToolWizardLocalePage#Locales"; + + private BuildToolWizardPluginPage fPage1; + private BuildToolWizardLocalePage fPage2; + private BuildToolWizardConfigurationPage fPage3; + + public BuildToolWizard() { + IDialogSettings master = Activator.getDefault().getDialogSettings(); + setDialogSettings(getSection(master)); + setWindowTitle(Messages.getString("Wizard_Title")); + } + + private IDialogSettings getSection(IDialogSettings master){ + IDialogSettings settings = master.getSection("BuildToolWizard"); + if(settings == null){ + return master.addNewSection("BuildToolWizard"); + } + return settings; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + BuildInitializationOperation runnable = new BuildInitializationOperation(selection, getDialogSettings().getArray(SELECTED_LOCALES)); + try { + PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); + } + catch (InvocationTargetException e) {e.printStackTrace();} + catch (InterruptedException e) {e.printStackTrace();} + finally { + if (runnable.wasCanceled()) { + return; + } + fPage1 = new BuildToolWizardPluginPage("BuildToolWizardPluginPage.Page1", runnable.getPluginsTable()); //$NON-NLS-1$ + fPage2 = new BuildToolWizardLocalePage("BuildToolWizardLocalePage.Page2", runnable.getLocalesTable()); //$NON-NLS-1$ + fPage3 = new BuildToolWizardConfigurationPage("BuildToolWizardConfigurationPage.Page3", runnable.getIgnoreTable(), runnable.getResourceExclusionTable()); //$NON-NLS-1$ + } + } + + public void addPages() { + addPage(fPage1); + addPage(fPage2); + addPage(fPage3); + } + + private String getGroupName(String nameWithDescription) { + if(nameWithDescription.startsWith("Group1")) { + return "Group1"; + } + else if(nameWithDescription.startsWith("Group2a")) { + return "Group2a"; + } + else if(nameWithDescription.startsWith("Group2")) { + return "Group2"; + } + else if(nameWithDescription.startsWith("GroupBidi")) { + return "GroupBidi"; + } + else { + return "All"; + } + + } + + public boolean performFinish() { + fPage1.storeSettings(); + fPage2.storeSettings(); + fPage3.storeSettings(); + + Object[] selectedPlugins; + String eclipseArchivePath; + + String[] selectedLocales; + + String workingDirectoryLocation; + String translationCataloguelocation; + Object[] ignoreList; + Object[] reportFilterPatterns; + boolean includeXmlReport; + boolean longReport; + + if(fPage1.isGeneratingFromPlugins()) { + selectedPlugins = fPage1.getSelectedPlugins(); + eclipseArchivePath = ""; + } + else { + eclipseArchivePath = fPage1.getEclipseArchiveLocation(); + selectedPlugins = null; + } + + if(fPage2.isGeneratingFromLocales()) { + if(fPage2.isGeneratingForAllLocales()) { + selectedLocales = new String[0]; + } + else { + Object[] locales = fPage2.getSelectedLocales(); + selectedLocales = new String[locales.length]; + for(int i=0; i<locales.length; i++) { + selectedLocales[i] = locales[i].toString(); + } + } + } + else { + selectedLocales = new String[]{getGroupName(fPage2.getSelectedGroup())}; + } + + workingDirectoryLocation = fPage3.getWorkingDirectoryLocation(); + translationCataloguelocation = fPage3.getTranslationCatalogueLocation(); + ignoreList = fPage3.getIgnoreList(); + reportFilterPatterns = fPage3.getReportFilterPatterns(); + includeXmlReport = fPage3.getXmlReportSelection(); + longReport = fPage3.getLongReportSelection(); + + final LanguagePackGenerationHandler handler; + + if(selectedPlugins == null) { + handler = new LanguagePackGenerationHandler(eclipseArchivePath, + selectedLocales, + workingDirectoryLocation, + translationCataloguelocation, + ignoreList, + reportFilterPatterns, + includeXmlReport, + longReport); + } + else { + handler = new LanguagePackGenerationHandler(selectedPlugins, + selectedLocales, + workingDirectoryLocation, + translationCataloguelocation, + ignoreList, + reportFilterPatterns, + includeXmlReport, + longReport); + } + + Job languagePackGenerationJob = new Job("Generating Language Pack") { + @Override + protected IStatus run(IProgressMonitor monitor) { + String errorMessage = handler.generateLanguagePack(monitor); + if (errorMessage.equals("")) { + return new Status(Status.OK, "Generating Language Pack", "Language pack successfully generated"); + } + return new Status(Status.ERROR, "Generating Language Pack", errorMessage); + } + }; + + languagePackGenerationJob.setPriority(Job.BUILD); + languagePackGenerationJob.schedule(); + + PlatformUI.getWorkbench().getProgressService().showInDialog(new Shell(), languagePackGenerationJob); + return true; + } + + @Override + public boolean canFinish() { + return fPage1.canFlipToNextPage() && fPage2.canFlipToNextPage() && fPage3.isPageComplete(); + } + + @Override + public IWizardPage getPreviousPage(IWizardPage currentPage) { + if (currentPage.equals(fPage3)) { + return fPage2; + } else if (currentPage.equals(fPage2)) { + return fPage1; + } + return null; + } + + @Override + public IWizardPage getNextPage(IWizardPage currentPage) { + if (currentPage.equals(fPage1)) { + return fPage2; + } else if (currentPage.equals(fPage2)) { + return fPage3; + } + return null; + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardConfigurationPage.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardConfigurationPage.java new file mode 100644 index 0000000..edf940a --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardConfigurationPage.java
@@ -0,0 +1,674 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +public class BuildToolWizardConfigurationPage extends BuildToolWizardPage { + + private static final String[] STRING = new String[]{}; + private static final String XML_REPORT = "BuildToolWizardConfigurationPage#fXMLReportGeneration"; + private static final String LONG_REPORT = "BuildToolWizardConfigurationPage#fLongReportGeneration"; + private static final String TRANSLATION_CATALOG_LOCATION = "BuildToolWizardConfigurationPage#fTranslationCatalogueLocationText"; + private static final String WORKING_DIRECTORY = "BuildToolWizardConfigurationPage#fWorkingDirectoryLocationText"; + private static final String IGNORE_LIST = "BuildToolWizardConfigurationPage#IgnoreList"; + private static final String IGNORE_LIST_CHECKED = "BuildToolWizardConfigurationPage#IgnoreListChecked"; + private static final String EXCLUDE_LIST = "BuildToolWizardConfigurationPage#ExcludeList"; + private static final String EXCLUDE_LIST_CHECKED = "BuildToolWizardConfigurationPage#ExcludeListChecked"; + + + private static final int VIEWER_WIDTH = 450; + private static final int VIEWER_HEIGHT = 110; + private static final int LIST_LABEL_INDENT = 6; + private static final int BUTTON_WIDTH = 110; + private static final int LIST_SEPARATOR = 20; + private static final int TEXT_WIDTH = 325; + private static final int LABEL_WIDTH = 190; + + private BuildToolModelTable fModelIgnoreTable; + private BuildToolModelTable fModelResourceExclusionTable; + + private Button fTranslationCatalogueBrowseButton; + private Button fWorkingDirectoryBrowseButton; + + private Label fWorkingDirectoryLocationLabel; + private Label fTranslationCatalogueLocationLabel; + + private Text fWorkingDirectoryLocationText; + private Text fTranslationCatalogueLocationText; + + private CheckboxTableViewer fLanguagePackResourceIgnoreViewer; + private Label fLanguagePackListLabel; + private Button fAddLanguagePackFilterButton; + private Button fRemoveLanguagePackFilterButton; + private String fChosenLanguagePackFilter; + + private CheckboxTableViewer fCoverageReportResourceFilterViewer; + private Label fCoverageReportListLabel; + private Button fAddCoverageReportFilterButton; + private Button fRemoveCoverageReportFilterButton; + private String fChosenCoverageReportFilter; + + private LanguagePackFilterDialog fLanguagePackFilterDialog; + private CoverageReportFilterDialog fCoverageReportFilterDialog; + private Button fLongReportGeneration; + private Button fXMLReportGeneration; + + private static ToT<Object,String> TO_STRING = new ToT<Object, String>() { + public String convert(Object from) { + return from.toString(); + } + }; + + private class TextModifyListener implements ModifyListener { + public void modifyText(ModifyEvent e) { + textSelectionChanged(); + } + } + + protected class IgnoreListContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object parent) { + return fModelIgnoreTable.getModels(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + protected class ExcludeListContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object parent) { + return fModelResourceExclusionTable.getModels(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + protected BuildToolWizardConfigurationPage(String pageName, BuildToolModelTable modelIgnoreTable, BuildToolModelTable modelExcludeTable) { + super(pageName); + this.fModelIgnoreTable = modelIgnoreTable; + this.fModelResourceExclusionTable = modelExcludeTable; + + this.setTitle(Messages.getString("BuildToolWizardConfigurationPage_PageTitle")); //$NON-NLS-1$ + this.setDescription(Messages.getString("BuildToolWizardConfigurationPage_PageDescription")); //$NON-NLS-1$ + } + + public void createControl(Composite parent) { + // Create a scrollable container to hold components + // This is useful when users are using a lower resolution. + ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); + Composite container = new Composite(comp, SWT.NONE); + container.setLayout(new GridLayout(1, false)); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createConfigurationArea(container); + + createLanguagePackFilteredListArea(container); + + createCoverageReportFilteredListArea(container); + + setControl(container); + Dialog.applyDialogFont(container); + setPageComplete(!"".equals(fWorkingDirectoryLocationText.getText()) && !"".equals(fTranslationCatalogueLocationText.getText())); + + // Scrollable container properties + comp.setContent(container); + comp.setMinHeight(500); + comp.setExpandHorizontal(true); + comp.setExpandVertical(true); + } + + private void createConfigurationArea(Composite parent) { + // Create a checkbox allowing for lightweight report generation + Composite longReportContainer = new Composite(parent, SWT.NONE); + longReportContainer.setLayout(new GridLayout(1, false)); + longReportContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); + createLongReportCheckbox(longReportContainer); + + // Create a checkbox allowing for xml report generation + Composite xmlReportContainer = new Composite(parent, SWT.NONE); + xmlReportContainer.setLayout(new GridLayout(1, false)); + xmlReportContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); + createXMLReportCheckbox(xmlReportContainer); + + // Create a place for specifying working directory + Composite workingDirectoryContainer = new Composite(parent, SWT.NONE); + workingDirectoryContainer.setLayout(new GridLayout(3, false)); + workingDirectoryContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); + createWorkingDirectoryBrowse(workingDirectoryContainer); + + // Create a place for specifying translation archive + Composite translationArchiveContainer = new Composite(parent, SWT.NONE); + translationArchiveContainer.setLayout(new GridLayout(3, false)); + translationArchiveContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); + createTranslationArchiveLocationBrowse(translationArchiveContainer); + } + + private void createLongReportCheckbox(Composite parent) { + fLongReportGeneration = new Button(parent, SWT.CHECK); + fLongReportGeneration.setText(Messages.getString("BuildToolWizardConfigurationPage_GenerateLongReportLabel")); + fLongReportGeneration.setSelection(getDialogSettings().getBoolean(LONG_REPORT)); + } + + private void createXMLReportCheckbox(Composite parent) { + fXMLReportGeneration = new Button(parent, SWT.CHECK); + fXMLReportGeneration.setText(Messages.getString("BuildToolWizardConfigurationPage_GenerateXMLReportLabel")); + fXMLReportGeneration.setSelection(getDialogSettings().getBoolean(XML_REPORT)); + } + + public boolean getLongReportSelection() { + return fLongReportGeneration.getSelection(); + } + + public boolean getXmlReportSelection() { + return fXMLReportGeneration.getSelection(); + } + + private void createTranslationArchiveLocationBrowse(Composite parent) { + fTranslationCatalogueLocationLabel = new Label(parent, SWT.NULL); + fTranslationCatalogueLocationLabel.setText(Messages.getString("BuildToolWizardConfigurationPage_TranslationCatalogueLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(); + gdLabel.widthHint = LABEL_WIDTH; + fTranslationCatalogueLocationLabel.setLayoutData(gdLabel); + + fTranslationCatalogueLocationText = new Text(parent, SWT.BORDER | SWT.SINGLE); + String location = not_null(getDialogSettings().get(TRANSLATION_CATALOG_LOCATION), ""); + fTranslationCatalogueLocationText.setText(location); + fTranslationCatalogueLocationText.addModifyListener(new TextModifyListener()); + GridData gdText = new GridData(GridData.FILL_HORIZONTAL); + gdText.widthHint = TEXT_WIDTH; + fTranslationCatalogueLocationText.setLayoutData(gdText); + + fTranslationCatalogueBrowseButton = new Button(parent, SWT.PUSH); + fTranslationCatalogueBrowseButton.setText(Messages.getString("BuildToolWizardConfigurationPage_TranslationCatalogueBrowseButton")); //$NON-NLS-1$ + + Listener listener = new Listener() { + public void handleEvent(Event event) { + DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell()); + dialog.setText(Messages.getString("BuildToolWizardConfigurationPage_TranslationCatalogueDialogTitle")); //$NON-NLS-1$ + dialog.setMessage(Messages.getString("BuildToolWizardConfigurationPage_TranslationCatalogueDialogMessage")); //$NON-NLS-1$ + String selectedFileName = dialog.open(); + if (selectedFileName != null) { + fTranslationCatalogueLocationText.setText(selectedFileName); + } + } + }; + + fTranslationCatalogueBrowseButton.addListener(SWT.Selection, listener); + } + + private void createWorkingDirectoryBrowse(Composite parent) { + fWorkingDirectoryLocationLabel = new Label(parent, SWT.NULL); + fWorkingDirectoryLocationLabel.setText(Messages.getString("BuildToolWizardConfigurationPage_WorkingDirectoryLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(); + gdLabel.widthHint = LABEL_WIDTH; + fWorkingDirectoryLocationLabel.setLayoutData(gdLabel); + + fWorkingDirectoryLocationText = new Text(parent, SWT.BORDER | SWT.SINGLE); + String location = not_null(getDialogSettings().get(WORKING_DIRECTORY), ""); + fWorkingDirectoryLocationText.setText(location); + fWorkingDirectoryLocationText.addModifyListener(new TextModifyListener()); + GridData gdText = new GridData(GridData.FILL_HORIZONTAL); + gdText.widthHint = TEXT_WIDTH; + fWorkingDirectoryLocationText.setLayoutData(gdText); + + fWorkingDirectoryBrowseButton = new Button(parent, SWT.PUSH); + fWorkingDirectoryBrowseButton.setText(Messages.getString("BuildToolWizardConfigurationPage_WorkingDirectoryBrowseButton")); //$NON-NLS-1$ + + Listener listener = new Listener() { + public void handleEvent(Event event) { + DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell()); + dialog.setText(Messages.getString("BuildToolWizardConfigurationPage_WorkingDirectoryDialogTitle")); //$NON-NLS-1$ + dialog.setMessage(Messages.getString("BuildToolWizardConfigurationPage_WorkingDirectoryDialogMessage")); //$NON-NLS-1$ + String selectedFileName = dialog.open(); + if (selectedFileName != null) { + fWorkingDirectoryLocationText.setText(selectedFileName); + } + } + }; + + fWorkingDirectoryBrowseButton.addListener(SWT.Selection, listener); + } + + private void createLanguagePackFilteredListArea(Composite parent) { + fLanguagePackListLabel = new Label(parent, SWT.NONE); + fLanguagePackListLabel.setText(Messages.getString("BuildToolWizardConfigurationPage_IgnoreListLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(GridData.FILL_HORIZONTAL); + gdLabel.widthHint = LABEL_WIDTH; + gdLabel.horizontalIndent = LIST_LABEL_INDENT; + gdLabel.verticalIndent = LIST_SEPARATOR; + fLanguagePackListLabel.setLayoutData(gdLabel); + + Composite listComposite = new Composite(parent, SWT.NONE); + listComposite.setLayout(new GridLayout(2, false)); + listComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Table table = new Table(listComposite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + table.setLayout(new TableLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = VIEWER_HEIGHT; + data.widthHint = VIEWER_WIDTH; + table.setLayoutData(data); + + fLanguagePackResourceIgnoreViewer = new CheckboxTableViewer(table); + fLanguagePackResourceIgnoreViewer.setLabelProvider(new LabelProvider()); + fLanguagePackResourceIgnoreViewer.setContentProvider(new IgnoreListContentProvider()); + fLanguagePackResourceIgnoreViewer.setInput(fModelIgnoreTable.getModels()); + fLanguagePackResourceIgnoreViewer.setComparator(new ViewerComparator()); + fLanguagePackResourceIgnoreViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + // Enable button only if there's a selection + if (event.getSelection().isEmpty()) { + fRemoveLanguagePackFilterButton.setEnabled(false); + } else { + fRemoveLanguagePackFilterButton.setEnabled(true); + } + } + }); + + // By default, all pre-defined patterns are checked + fLanguagePackResourceIgnoreViewer.setAllChecked(true); + + createLanguagePackFilteredListControlButtonsArea(listComposite); + } + + private void createLanguagePackFilteredListControlButtonsArea(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1, false)); + GridData gData = new GridData(); + buttonComposite.setLayoutData(gData); + + GridData gdText = new GridData(); + gdText.widthHint = BUTTON_WIDTH; + + // Add Pattern Button + fAddLanguagePackFilterButton = new Button(buttonComposite, SWT.PUSH); + fAddLanguagePackFilterButton.setText(Messages.getString("BuildToolWizardConfigurationPage_AddLanguagePackFilterButton")); + fAddLanguagePackFilterButton.setLayoutData(gdText); + fAddLanguagePackFilterButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + openLanguagePackFilterDialog(); + } + }); + + // Remove Pattern Button + fRemoveLanguagePackFilterButton = new Button(buttonComposite, SWT.PUSH); + fRemoveLanguagePackFilterButton.setText(Messages.getString("BuildToolWizardConfigurationPage_RemoveLanguagePackFilterButton")); + fRemoveLanguagePackFilterButton.setLayoutData(gdText); + fRemoveLanguagePackFilterButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeSelectedLanguagePackFilter(); + } + }); + fRemoveLanguagePackFilterButton.setEnabled(false); + + Button selectAll = new Button(buttonComposite, SWT.PUSH); + selectAll.setText(Messages.getString("BuildToolWizardConfigurationPage_SelectAllLanguagePackFiltersButton")); + selectAll.setLayoutData(gdText); + selectAll.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + fLanguagePackResourceIgnoreViewer.setAllChecked(true); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + Button deselectAll = new Button(buttonComposite, SWT.PUSH); + deselectAll.setText(Messages.getString("BuildToolWizardConfigurationPage_DeselectAllLanguagePackFiltersButton")); + deselectAll.setLayoutData(gdText); + deselectAll.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + fLanguagePackResourceIgnoreViewer.setAllChecked(false); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + IDialogSettings settings = getDialogSettings(); + for(String filter : not_null(settings.getArray(IGNORE_LIST), new String[]{})){ + addLanguagePackFilter(filter, false); + } + + for(String checked : not_null(settings.getArray(IGNORE_LIST_CHECKED), new String[]{})){ + addLanguagePackFilter(checked, true); + } + } + + private void createCoverageReportFilteredListArea(Composite parent) { + fCoverageReportListLabel = new Label(parent, SWT.NONE); + fCoverageReportListLabel.setText(Messages.getString("BuildToolWizardConfigurationPage_FilterListLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(GridData.FILL_HORIZONTAL); + gdLabel.widthHint = LABEL_WIDTH; + gdLabel.horizontalIndent = LIST_LABEL_INDENT; + gdLabel.verticalIndent = LIST_SEPARATOR; + fCoverageReportListLabel.setLayoutData(gdLabel); + + Composite listComposite = new Composite(parent, SWT.NONE); + listComposite.setLayout(new GridLayout(2, false)); + listComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Table table = new Table(listComposite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + table.setLayout(new TableLayout()); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = VIEWER_HEIGHT; + data.widthHint = VIEWER_WIDTH; + table.setLayoutData(data); + + fCoverageReportResourceFilterViewer = new CheckboxTableViewer(table); + fCoverageReportResourceFilterViewer.setLabelProvider(new LabelProvider()); + fCoverageReportResourceFilterViewer.setContentProvider(new ExcludeListContentProvider()); + fCoverageReportResourceFilterViewer.setInput(fModelResourceExclusionTable.getModels()); + fCoverageReportResourceFilterViewer.setComparator(new ViewerComparator()); + fCoverageReportResourceFilterViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + // Enable button only if there's a selection + if (event.getSelection().isEmpty()) { + fRemoveCoverageReportFilterButton.setEnabled(false); + } else { + fRemoveCoverageReportFilterButton.setEnabled(true); + } + } + }); + + // By default, all pre-defined filters are checked + fCoverageReportResourceFilterViewer.setAllChecked(true); + + // Create an area with buttons for adding/removing resource patterns, and for selecting/deselecting all + createExcludeListControlButtonArea(listComposite); + + IDialogSettings settings = getDialogSettings(); + for(String filter : not_null(settings.getArray(EXCLUDE_LIST), new String[]{})){ + addCoverageReportFilter(filter, false); + } + + for(String checked : not_null(settings.getArray(EXCLUDE_LIST_CHECKED), new String[]{})){ + addCoverageReportFilter(checked, true); + } + } + + private void createExcludeListControlButtonArea(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1, false)); + GridData gData = new GridData(); + buttonComposite.setLayoutData(gData); + + GridData gdText = new GridData(); + gdText.widthHint = BUTTON_WIDTH; + + // Add Pattern Button + fAddCoverageReportFilterButton = new Button(buttonComposite, SWT.PUSH); + fAddCoverageReportFilterButton.setText(Messages.getString("BuildToolWizardConfigurationPage_AddCoverageReportFilterButton")); + fAddCoverageReportFilterButton.setLayoutData(gdText); + fAddCoverageReportFilterButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + openCoverageReportFilterDialog(); + } + }); + + // Remove Pattern Button + fRemoveCoverageReportFilterButton = new Button(buttonComposite, SWT.PUSH); + fRemoveCoverageReportFilterButton.setText(Messages.getString("BuildToolWizardConfigurationPage_RemoveCoverageReportFilterButton")); + fRemoveCoverageReportFilterButton.setLayoutData(gdText); + fRemoveCoverageReportFilterButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeSelectedCoverageReportFilter(); + } + }); + fRemoveCoverageReportFilterButton.setEnabled(false); + + Button selectAll = new Button(buttonComposite, SWT.PUSH); + selectAll.setText(Messages.getString("BuildToolWizardConfigurationPage_SelectAllCoverageReportFiltersButton")); + selectAll.setLayoutData(gdText); + selectAll.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + fCoverageReportResourceFilterViewer.setAllChecked(true); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + Button deselectAll = new Button(buttonComposite, SWT.PUSH); + deselectAll.setText(Messages.getString("BuildToolWizardConfigurationPage_DeselectAllCoverageReportFiltersButton")); + deselectAll.setLayoutData(gdText); + deselectAll.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + fCoverageReportResourceFilterViewer.setAllChecked(false); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + } + + public void setCoverageReportFilter(String filter) { + this.fChosenCoverageReportFilter = filter; + } + + public void setLanguagePackFilter(String filter) { + this.fChosenLanguagePackFilter = filter; + } + + private void openLanguagePackFilterDialog() { + Shell shell = new Shell(this.getShell(), SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); + + fLanguagePackFilterDialog = new LanguagePackFilterDialog(shell, this); + fLanguagePackFilterDialog.getParent().open(); + fLanguagePackFilterDialog.getParent().addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + // If a pattern was provided through the dialog, handle. + if ((fChosenLanguagePackFilter != null) && (fChosenLanguagePackFilter.trim().compareTo("") != 0)) { + addLanguagePackFilter(fChosenLanguagePackFilter); + } + fChosenLanguagePackFilter = null; + } + }); + } + + private void addCoverageReportFilter(String o){ + addCoverageReportFilter(o, true); + } + + private void addCoverageReportFilter(String o, boolean checked) { + boolean doesItemExist = false; + + // Check if extension is already in the ignore list + for (TableItem item: fCoverageReportResourceFilterViewer.getTable().getItems()) { + if (item.getText().compareToIgnoreCase(o) == 0) { + doesItemExist = true; + } + } + + // Only add an item if its name does not conflict with an item + // that is already in the list. + if (!doesItemExist) { + fModelResourceExclusionTable.addModel(o); + fCoverageReportResourceFilterViewer.add(o); + fCoverageReportResourceFilterViewer.refresh(); + } + // Ensure new item is checked + fCoverageReportResourceFilterViewer.setChecked(o, checked); + } + + private void addLanguagePackFilter(String o){ + addLanguagePackFilter(o, true); + } + + private void addLanguagePackFilter(String o, boolean checked) { + boolean doesItemExist = false; + + // Check if extension is already in the ignore list + for (TableItem item: fLanguagePackResourceIgnoreViewer.getTable().getItems()) { + if (item.getText().compareToIgnoreCase(o) == 0) { + doesItemExist = true; + } + } + + // Only add an item if its name does not conflict with an item + // that is already in the list. + if (!doesItemExist) { + fModelIgnoreTable.addModel(o); + fLanguagePackResourceIgnoreViewer.add(o); + fLanguagePackResourceIgnoreViewer.refresh(); + } + fLanguagePackResourceIgnoreViewer.setChecked(o, checked); + } + + private void removeSelectedLanguagePackFilter() { + int selectionIndex = fLanguagePackResourceIgnoreViewer.getTable().getSelectionIndex(); + if (selectionIndex != -1) { + Object o = fLanguagePackResourceIgnoreViewer.getElementAt(selectionIndex); + + fModelIgnoreTable.removeModel(o); + fLanguagePackResourceIgnoreViewer.remove(o); + + fLanguagePackResourceIgnoreViewer.refresh(); + } + } + + private void removeSelectedCoverageReportFilter() { + int selectionIndex = fCoverageReportResourceFilterViewer.getTable().getSelectionIndex(); + if (selectionIndex != -1) { + Object o = fCoverageReportResourceFilterViewer.getElementAt(selectionIndex); + + fModelResourceExclusionTable.removeModel(o); + fCoverageReportResourceFilterViewer.remove(o); + + fCoverageReportResourceFilterViewer.refresh(); + } + } + + private void openCoverageReportFilterDialog() { + Shell shell = new Shell(this.getShell(), SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); + + // Start up custom AddPatternDialog which requests a custom pattern + fCoverageReportFilterDialog = new CoverageReportFilterDialog(shell, this); + fCoverageReportFilterDialog.getParent().open(); + fCoverageReportFilterDialog.getParent().addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + // If a pattern was provided through the custom dialog, handle. + if ((fChosenCoverageReportFilter != null) && (fChosenCoverageReportFilter.trim().compareTo("") != 0)) { + addCoverageReportFilter(fChosenCoverageReportFilter); + } + fChosenCoverageReportFilter = null; + } + }); + } + + private void textSelectionChanged() { + setPageComplete((fWorkingDirectoryLocationText.getText().length() > 0) + && (fTranslationCatalogueLocationText.getText().length() > 0)); + } + + public String getWorkingDirectoryLocation() { + return fWorkingDirectoryLocationText.getText(); + } + + public String getTranslationCatalogueLocation() { + return fTranslationCatalogueLocationText.getText(); + } + + public Object[] getIgnoreList() { + return fLanguagePackResourceIgnoreViewer.getCheckedElements(); + } + + public Object[] getReportFilterPatterns() { + return fCoverageReportResourceFilterViewer.getCheckedElements(); + } + + public boolean isCurrentPage() { + return super.isCurrentPage(); + } + + public boolean canFlipToNextPage() { + return false; + } + + private String[] getAllElements(CheckboxTableViewer viewer){ + List<String> elements = new LinkedList<String>(); + Object o; + int i = 0; + while((o = viewer.getElementAt(i++)) != null){ + elements.add(o.toString()); + } + + return elements.toArray(STRING); + } + + private static interface ToT<F,T>{ + public T convert(F from); + } + + private <F,T> T[] convert(T[] array, ToT<F,T> toT, F... fs){ + List<T> ts = new LinkedList<T>(); + + for(F f : fs){ + ts.add(toT.convert(f)); + } + + return ts.toArray(array); + } + + @Override + public void storeSettings() { + IDialogSettings settings = getDialogSettings(); + settings.put(XML_REPORT, fXMLReportGeneration.getSelection()); + settings.put(LONG_REPORT, fLongReportGeneration.getSelection()); + settings.put(TRANSLATION_CATALOG_LOCATION, fTranslationCatalogueLocationText.getText()); + settings.put(WORKING_DIRECTORY, fWorkingDirectoryLocationText.getText()); + settings.put(IGNORE_LIST, getAllElements(fLanguagePackResourceIgnoreViewer)); + settings.put(IGNORE_LIST_CHECKED, convert(STRING, TO_STRING, fLanguagePackResourceIgnoreViewer.getCheckedElements())); + + settings.put(EXCLUDE_LIST, getAllElements(fCoverageReportResourceFilterViewer)); + settings.put(EXCLUDE_LIST_CHECKED, convert(STRING, TO_STRING, fCoverageReportResourceFilterViewer.getCheckedElements())); + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardLocalePage.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardLocalePage.java new file mode 100644 index 0000000..caa9105 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardLocalePage.java
@@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; + +public class BuildToolWizardLocalePage extends BuildToolWizardPage { + + private final static String FILTER_PATTERN = "BuildToolWizardLocalePage#fLocaleFilter"; + private final static String SELECTED_LOCALES = "BuildToolWizardLocalePage#Locales"; + private final static String ALL_LOCALES = "BuildToolWizardLocalePage#fAllLocalesCheckbox"; + private final static String BY_GROUP = "BuildToolWizardLocalePage#fLocaleGroupCheckbox"; + private final static String SELECTED_GROUP = "BuildToolWizardLocalePage#fLocaleGroupCombo"; + + private BuildToolModelTable fModelLocalesTable; + + private Button fAllLocalesCheckbox; + private Button fLocaleGroupCheckbox; + private Label fLocaleGroupLabel; + private Combo fLocaleGroupCombo; + + private FilteredListComponent fLocaleFilter; + + private class GroupCheckboxSelectionListener implements SelectionListener { + public void widgetSelected(SelectionEvent e){ + groupCheckboxSelectionChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e){ + } + } + + private class AllLocalesCheckboxSelectionListener implements SelectionListener { + public void widgetSelected(SelectionEvent e){ + allLocalesCheckboxSelectionChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e){ + } + } + + protected BuildToolWizardLocalePage(String pageName, BuildToolModelTable modelLocalesTable) { + super(pageName); + this.fModelLocalesTable = modelLocalesTable; + + this.setTitle(Messages.getString("BuildToolWizardLocalePage_PageTitle")); //$NON-NLS-1$ + this.setDescription(Messages.getString("BuildToolWizardLocalePage_PageDescription")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + // Create filtered list component + fLocaleFilter = new FilteredListComponent(fModelLocalesTable, new LocaleLabelProvider(), this); + Composite container = fLocaleFilter.createFilteredListComponent(parent); + + createAllLocalesCheckbox(container); + + createLocaleGroupArea(container); + + setControl(container); + Dialog.applyDialogFont(container); + + allLocalesCheckboxSelectionChanged(); + groupCheckboxSelectionChanged(); + + try { + int selectedIndex = getDialogSettings().getInt(SELECTED_GROUP); + fLocaleGroupCombo.select(selectedIndex); + } catch(NumberFormatException e) { } + + String pattern = not_null(getDialogSettings().get(FILTER_PATTERN), ""); + fLocaleFilter.fFilterText.setText(pattern); + } + + private void createAllLocalesCheckbox(Composite container) { + fAllLocalesCheckbox = new Button(container, SWT.CHECK); + GridData bLayout = new GridData(); + bLayout.horizontalIndent = 6; + bLayout.horizontalSpan = 3; + fAllLocalesCheckbox.setLayoutData(bLayout); + fAllLocalesCheckbox.setText(Messages.getString("BuildToolWizardLocalePage_AllLocaleCheckbox")); + fAllLocalesCheckbox.addSelectionListener(new AllLocalesCheckboxSelectionListener()); + fAllLocalesCheckbox.setSelection(getDialogSettings().getBoolean(ALL_LOCALES)); + } + + private void createLocaleGroupArea(Composite parent) { + Group container = new Group(parent, SWT.NONE); + FillLayout layout = new FillLayout(SWT.VERTICAL); + layout.marginHeight = layout.marginWidth = 12; + container.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + container.setLayoutData(gd); + + Composite container1 = new Composite(container, SWT.NONE); + container1.setLayout(new GridLayout(1, false)); + + Composite container2 = new Composite(container, SWT.NONE); + container2.setLayout(new GridLayout(3, false)); + + createLocaleGroupCheckbox(container1); + createLocaleGroupDropdown(container2); + } + + private void createLocaleGroupCheckbox(Composite container) { + fLocaleGroupCheckbox = new Button(container, SWT.CHECK); + fLocaleGroupCheckbox.setText(Messages.getString("BuildToolWizardLocalePage_GenerateForLocaleGroupLabel")); //$NON-NLS-1$ + fLocaleGroupCheckbox.addSelectionListener(new GroupCheckboxSelectionListener()); + fLocaleGroupCheckbox.setSelection(getDialogSettings().getBoolean(BY_GROUP)); + } + + private void createLocaleGroupDropdown(Composite container) { + fLocaleGroupLabel = new Label(container, SWT.NONE); + fLocaleGroupLabel.setText(Messages.getString("BuildToolWizardLocalePage_LocaleGroupLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(); + gdLabel.horizontalIndent = 30; + fLocaleGroupLabel.setLayoutData(gdLabel); + + fLocaleGroupCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY); + GridData gdText = new GridData(GridData.FILL_HORIZONTAL); + gdText.widthHint = 300; + fLocaleGroupCombo.setLayoutData(gdText); + + fLocaleGroupCombo.add("All groups"); //$NON-NLS-1$ + fLocaleGroupCombo.add("Group1: de, es, fr, it, ja, ko, pt_BR, zh, zh_HK, zh_TW"); //$NON-NLS-1$ + fLocaleGroupCombo.add("Group2: cs, hu, pl, ru"); //$NON-NLS-1$ + fLocaleGroupCombo.add("Group2a: da, el, fi, nl, no, pt, sv, tr"); //$NON-NLS-1$ + fLocaleGroupCombo.add("GroupBidi: ar, iw"); //$NON-NLS-1$ + fLocaleGroupCombo.setText("All groups"); //$NON-NLS-1$ + +// enableLocaleGroupArea(false); + } + + private void groupCheckboxSelectionChanged() { + if(fLocaleGroupCheckbox.getSelection()) { + enableLocaleGroupArea(true); + enableLocaleArea(false); + + setPageComplete(true); + } + else { + enableLocaleGroupArea(false); + enableLocaleArea(true); + } + } + + private void allLocalesCheckboxSelectionChanged() { + if(fAllLocalesCheckbox.getSelection()) { + fLocaleFilter.setEnabled(false); + setPageComplete(true); + } + else { + fLocaleFilter.setEnabled(true); + setPageComplete(fLocaleFilter.getSelectedViewer().getTable().getItemCount() > 0); + } + } + + private void enableLocaleGroupArea(boolean enable) { + fLocaleGroupCombo.setEnabled(enable); + } + + private void enableLocaleArea(boolean enable) { + if(enable) { + fAllLocalesCheckbox.setEnabled(true); + if(fAllLocalesCheckbox.getSelection()) { + fLocaleFilter.setEnabled(false); + setPageComplete(true); + } + else { + fLocaleFilter.setEnabled(true); + setPageComplete(fLocaleFilter.getSelectedViewer().getTable().getItemCount() > 0); + } + } + else { + fLocaleFilter.setEnabled(false); + fAllLocalesCheckbox.setEnabled(false); + } + } + + public boolean isGeneratingFromLocales() { + return !fLocaleGroupCheckbox.getSelection(); + } + + public boolean isGeneratingForAllLocales() { + return fAllLocalesCheckbox.getSelection(); + } + + public Object[] getSelectedLocales() { + return this.fLocaleFilter.getSelected(); + } + + public String getSelectedGroup() { + return this.fLocaleGroupCombo.getText(); + } + + public boolean isCurrentPage() { + return super.isCurrentPage(); + } + + public boolean canFlipToNextPage() { + if(fAllLocalesCheckbox.getSelection() || fLocaleFilter.hasSelectedItems()){ + return true; + } + + if(fLocaleGroupCheckbox.getSelection()) { + return true; + } + return false; + } + + @Override + public void storeSettings() { + Object[] objs = getSelectedLocales(); + String[] locales = new String[objs.length]; + int current = 0; + for(Object o : objs){ + locales[current++] = o.toString(); + } + + IDialogSettings settings = getDialogSettings(); + settings.put(FILTER_PATTERN, fLocaleFilter.fFilterText.getText()); + settings.put(SELECTED_LOCALES, locales); + settings.put(ALL_LOCALES, fAllLocalesCheckbox.getSelection()); + settings.put(BY_GROUP, fLocaleGroupCheckbox.getSelection()); + + int selectionIndex = fLocaleGroupCombo.getSelectionIndex(); + if (selectionIndex != -1) { + settings.put(SELECTED_GROUP, fLocaleGroupCombo.getSelectionIndex()); + } + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPage.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPage.java new file mode 100644 index 0000000..4405bd3 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPage.java
@@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.pde.core.IModelProviderEvent; +import org.eclipse.pde.core.IModelProviderListener; +import org.eclipse.swt.widgets.Composite; + +public class BuildToolWizardPage extends WizardPage implements IModelProviderListener{ + + public BuildToolWizardPage(String pageName) { + super(pageName); + } + + public void createControl(Composite parent) { + } + + public void modelsChanged(IModelProviderEvent event) { + } + + public void storeSettings(){} + + protected <T> T not_null(T... ts) { + for(T t : ts){ + if(t != null){ + return t; + } + } + return null; + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPluginPage.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPluginPage.java new file mode 100644 index 0000000..9761e9e --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/BuildToolWizardPluginPage.java
@@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; + +public class BuildToolWizardPluginPage extends BuildToolWizardPage { + + private static final String EXTERNAL_ECLIPSE_CHECKBOX = "BuildToolWizardPluginPage#fEclipseInstallCheckbox"; + private static final String EXTERNAL_ECLIPSE_LOCATION = "BuildToolWizardPluginPage#fEclipseArchiveLocationText"; + private static final String FILTER_PATTERN = "BuildToolWizardPluginPage#fPluginFilter"; + + private static final int MARGIN = 12; + private static final int LABEL_WIDTH = 30; + private static final int TEXTBOX_WIDTH = 300; + private static final String[] fEclipseArchiveExtensions = new String[] { "*.zip" }; //$NON-NLS-1$ + + private BuildToolModelTable fModelPluginsTable; + + private Button fEclipseInstallCheckbox; + private Button fEclipseArchiveBrowseButton; + private Text fEclipseArchiveLocationText; + private Label fEclipseArchiveLocationLabel; + + private FilteredListComponent fPluginFilter; + + private class TextModifyListener implements ModifyListener { + public void modifyText(ModifyEvent e) { + textSelectionChanged(); + } + } + + private class CheckboxSelectionListener implements SelectionListener { + public void widgetSelected(SelectionEvent e){ + checkboxSelectionChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e){ + + } + } + + protected BuildToolWizardPluginPage(String pageName, BuildToolModelTable modelPluginsTable) { + super(pageName); + this.fModelPluginsTable = modelPluginsTable; + + this.setTitle(Messages.getString("BuildToolWizardPluginPage_PageTitle")); //$NON-NLS-1$ + this.setDescription(Messages.getString("BuildToolWizardPluginPage_PageDescription")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + // Create filtered list component + fPluginFilter = new FilteredListComponent(fModelPluginsTable, new PluginLabelProvider(), this); + Composite container = fPluginFilter.createFilteredListComponent(parent); + + createEclipseInstallArea(container); + + setControl(container); + Dialog.applyDialogFont(container); + + checkboxSelectionChanged(); + + String pattern = not_null(getDialogSettings().get(FILTER_PATTERN), ""); + fPluginFilter.fFilterText.setText(pattern); + } + + private void createEclipseInstallArea(Composite parent) { + Group container = new Group(parent, SWT.NONE); + FillLayout layout = new FillLayout(SWT.VERTICAL); + layout.marginHeight = layout.marginWidth = MARGIN; + container.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + container.setLayoutData(gd); + + Composite container1 = new Composite(container, SWT.NONE); + container1.setLayout(new GridLayout(1, false)); + + Composite container2 = new Composite(container, SWT.NONE); + container2.setLayout(new GridLayout(3, false)); + + createEclipseInstallCheckbox(container1); + createEclipseInstallBrowse(container2); + } + + private void createEclipseInstallCheckbox(Composite container) { + IDialogSettings settings = getDialogSettings(); + boolean isSelected = settings.getBoolean(EXTERNAL_ECLIPSE_CHECKBOX); + fEclipseInstallCheckbox = new Button(container, SWT.CHECK); + fEclipseInstallCheckbox.setText(Messages.getString("BuildToolWizardPluginPage_GenerateFromArchiveLabel")); //$NON-NLS-1$ + fEclipseInstallCheckbox.addSelectionListener(new CheckboxSelectionListener()); + fEclipseInstallCheckbox.setSelection(isSelected); + } + + private void createEclipseInstallBrowse(Composite container) { + IDialogSettings settings = getDialogSettings(); + String archiveLocation = not_null(settings.get(EXTERNAL_ECLIPSE_LOCATION), ""); + + fEclipseArchiveLocationLabel = new Label(container, SWT.NONE); + fEclipseArchiveLocationLabel.setText(Messages.getString("BuildToolWizardPluginPage_ExternalArchiveLocationLabel")); //$NON-NLS-1$ + GridData gdLabel = new GridData(); + gdLabel.horizontalIndent = LABEL_WIDTH; + fEclipseArchiveLocationLabel.setLayoutData(gdLabel); + + fEclipseArchiveLocationText = new Text(container, SWT.BORDER | SWT.SINGLE); + fEclipseArchiveLocationText.setText(archiveLocation); + fEclipseArchiveLocationText.addModifyListener(new TextModifyListener()); + GridData gdText = new GridData(GridData.FILL_HORIZONTAL); + gdText.widthHint = TEXTBOX_WIDTH; + fEclipseArchiveLocationText.setLayoutData(gdText); + + + fEclipseArchiveBrowseButton = new Button(container, SWT.PUSH); + fEclipseArchiveBrowseButton.setText(Messages.getString("BuildToolWizardPluginPage_BrowseButton")); //$NON-NLS-1$ + + Listener listener = new Listener() { + public void handleEvent(Event event) { + FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.OPEN); + dialog.setText(Messages.getString("BuildToolWizardPluginPage_SelectEclipseArchiveDialogTitle")); //$NON-NLS-1$ + dialog.setFilterExtensions(fEclipseArchiveExtensions ); //$NON-NLS-1$ + String selectedFileName = dialog.open(); + if (selectedFileName != null) { + fEclipseArchiveLocationText.setText(selectedFileName); + } + } + }; + + fEclipseArchiveBrowseButton.addListener(SWT.Selection, listener); + enableEclipseInstallLocationArea(false); + } + + private void textSelectionChanged() { + setPageComplete(fEclipseArchiveLocationText.getText().length() > 0); + } + + private void checkboxSelectionChanged() { + if(fEclipseInstallCheckbox.getSelection()) { + enableEclipseInstallLocationArea(true); + fPluginFilter.setEnabled(false); + + setPageComplete(fEclipseArchiveLocationText.getText().length() > 0); + } + else { + enableEclipseInstallLocationArea(false); + fPluginFilter.setEnabled(true); + + setPageComplete(fPluginFilter.getSelectedViewer().getTable().getItemCount() > 0); + } + } + + private void enableEclipseInstallLocationArea(boolean enable) { + fEclipseArchiveLocationText.setEnabled(enable); + fEclipseArchiveBrowseButton.setEnabled(enable); + } + + public String getEclipseArchiveLocation() { + return this.fEclipseArchiveLocationText.getText(); + } + + public Object[] getSelectedPlugins() { + return this.fPluginFilter.getSelected(); + } + + public boolean isGeneratingFromPlugins() { + return !fEclipseInstallCheckbox.getSelection(); + } + + public boolean isCurrentPage() { + return super.isCurrentPage(); + } + + @Override + public boolean canFlipToNextPage() { + if(!fEclipseInstallCheckbox.getSelection() && fPluginFilter.hasSelectedItems()){ + return true; + } + else if(fEclipseInstallCheckbox.getSelection() && fEclipseArchiveLocationText.getText().length() > 0) { + return true; + } + return false; + } + + @Override + public void storeSettings() { + IDialogSettings settings = getDialogSettings(); + settings.put(EXTERNAL_ECLIPSE_CHECKBOX, fEclipseInstallCheckbox.getSelection()); + settings.put(EXTERNAL_ECLIPSE_LOCATION, fEclipseArchiveLocationText.getText()); + settings.put(FILTER_PATTERN, fPluginFilter.fFilterText.getText()); + } +} \ No newline at end of file
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/CoverageReportFilterDialog.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/CoverageReportFilterDialog.java new file mode 100644 index 0000000..7e506ad --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/CoverageReportFilterDialog.java
@@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.swt.widgets.Shell; + +public class CoverageReportFilterDialog extends FilterDialog { + + public CoverageReportFilterDialog(final Shell parent, final BuildToolWizardConfigurationPage caller) { + super(parent, caller); + + parent.setText(Messages.getString("CoverageReportFilterDialog_Title")); + } + + protected void setChosenFilter(String filter) { + fCallingPage.setCoverageReportFilter(filter); + } +} + +
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilterDialog.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilterDialog.java new file mode 100644 index 0000000..cf945e3 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilterDialog.java
@@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public abstract class FilterDialog extends Dialog { + + protected static final int DIALOG_POSITION_Y = 350; + protected static final int DIALOG_POSITION_X = 425; + protected static final int DIALOG_HEIGHT = 115; + protected static final int DIALOG_WIDTH = 425; + + protected Label fAddLabel; + protected Text fAddText; + protected Button fAddButton; + protected Button fCancelButton; + + protected BuildToolWizardConfigurationPage fCallingPage; + + protected Label fErrorLabel; + + public FilterDialog(final Shell parent, final BuildToolWizardConfigurationPage caller) { + super(parent); + + this.fCallingPage = caller; + + parent.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); + parent.setLocation(DIALOG_POSITION_X, DIALOG_POSITION_Y); + + // Set layouts + parent.setLayout(new GridLayout(1, false)); + parent.setLayoutData(new GridData()); + + // Label describes what is expected + createLabelArea(parent); + + // Text allows user to enter a pattern + createTextboxArea(parent); + + // Create a button area for adding + createButtonArea(parent); + } + + protected void createLabelArea(final Shell parent) { + fAddLabel = new Label(parent, SWT.NONE); + fAddLabel.setText(Messages.getString("FilterDialog_EnterPatternLabel")); + + GridData gdLabel = new GridData(GridData.FILL_HORIZONTAL); + gdLabel.widthHint = 400; + fAddLabel.setLayoutData(gdLabel); + } + + protected void createTextboxArea(final Shell parent) { + fAddText = new Text(parent, SWT.BORDER | SWT.SINGLE); + + GridData gdText = new GridData(GridData.FILL_HORIZONTAL); + gdText.widthHint = 400; + fAddText.setLayoutData(gdText); + } + + protected void createButtonArea(final Shell parent) { + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(3, false)); + + GridData gdLabel = new GridData(); + gdLabel.widthHint = 240; + + fErrorLabel = new Label(container, SWT.NONE); + fErrorLabel.setLayoutData(gdLabel); + fErrorLabel.setForeground(new Color(null, new RGB(255,0,0))); + fErrorLabel.setText(Messages.getString("FilterDialog_PatternValidationError")); + fErrorLabel.setVisible(false); + + GridData gdButton = new GridData(); + gdButton.widthHint = 75; + + fAddButton = new Button(container, SWT.PUSH); + fAddButton.setText(Messages.getString("Common_AddButton")); + fAddButton.setLayoutData(gdButton); + fAddButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + try { + fErrorLabel.setVisible(false); + Pattern.compile(fAddText.getText()); + setChosenFilter(fAddText.getText()); + parent.dispose(); + } catch (PatternSyntaxException ex) { + fErrorLabel.setVisible(true); + } + } + }); + + fCancelButton = new Button(container, SWT.PUSH); + fCancelButton.setText(Messages.getString("Common_CancelButton")); + fCancelButton.setLayoutData(gdButton); + fCancelButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + parent.dispose(); + } + }); + + parent.setDefaultButton(fAddButton); + } + + protected abstract void setChosenFilter(String filter); +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilteredListComponent.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilteredListComponent.java new file mode 100644 index 0000000..9c70dab --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/FilteredListComponent.java
@@ -0,0 +1,530 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.progress.WorkbenchJob; + +public class FilteredListComponent { + + private Button fAddButton; + private Button fAddAllButton; + private Button fRemoveButton; + private Button fRemoveAllButton; + private Label fCountLabel; + + protected WorkbenchJob fFilterJob; + protected Text fFilterText; + protected ListFilter fFilter; + + private boolean fBlockSelectionListeners; + + protected TableViewer fAvailableViewer; + protected TableViewer fSelectedViewer; + + protected HashMap<Object, Object> fSelected; + protected Composite fHighLevelContainer; + + protected LabelProvider fLabelProvider; + protected boolean fEnabled; + + protected BuildToolWizardPage fParentPage; + protected BuildToolModelTable fModelTable; + + protected class ContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object parent) { + return fModelTable.getModels(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + protected class SelectedContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object parent) { + return fModelTable.getPreSelected(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + protected FilteredListComponent(BuildToolModelTable modelTable, LabelProvider labelProvider, BuildToolWizardPage parentPage) { + this.fModelTable = modelTable; + this.fLabelProvider = labelProvider; + this.fParentPage = parentPage; + + fEnabled = true; + fSelected = new HashMap<Object, Object>(); + } + + protected GridLayout getComponentLayout() { + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + layout.horizontalSpacing = 5; + layout.verticalSpacing = 20; + return layout; + } + + private GridLayout getViewerLayout() { + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + return layout; + } + + public Composite createFilteredListComponent(Composite parent) { + GridLayout gridLayout = getComponentLayout(); + + fHighLevelContainer = new Composite(parent, SWT.NONE); + fHighLevelContainer.setLayout(gridLayout); + + // Create filter area component + createFilterArea(fHighLevelContainer); + + // Create available plug-in list component + createAvailableList(fHighLevelContainer); + + // Create control button area component + createControlButtonArea(fHighLevelContainer); + + // Create selected plug-in list component + createSelectedList(fHighLevelContainer); + + // Add viewer listeners + addViewerListeners(); + + addFilter(); + + updateCount(); + + initialize(); + + return fHighLevelContainer; + } + + private void addFilter() { + fFilter = new ListFilter(fSelected, fLabelProvider); + fAvailableViewer.addFilter(fFilter); + fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + handleFilter(); + return Status.OK_STATUS; + } + }; + fFilterJob.setSystem(true); + } + + protected Composite createFilterArea(Composite parent) { + Group container = createFilterContainer(parent); + fFilterText = createFilterText(container, ""); //$NON-NLS-1$ + return container; + } + + private Group createFilterContainer(Composite parent) { + Group container = new Group(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = layout.marginHeight = 6; + container.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + container.setLayoutData(gd); + container.setText(Messages.getString("FilteredListComponent_FilterAvailableListLabel")); //$NON-NLS-1$ + return container; + } + + private Text createFilterText(Composite parent, String initial) { + Label filter = new Label(parent, SWT.NONE); + filter.setText(Messages.getString("FilteredListComponent_FilterDescriptionLabel")); //$NON-NLS-1$ + + Text text = new Text(parent, SWT.BORDER); + text.setText(initial); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + text.setLayoutData(gd); + return text; + } + + protected Composite createAvailableList(Composite parent) { + Composite container = createViewerContainer(parent, Messages.getString("FilteredListComponent_AvailableListLabel")); //$NON-NLS-1$ + fAvailableViewer = createTableViewer(container, new ContentProvider(), fModelTable.getModels()); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + if(fModelTable.getModels().length > 0) { + fAvailableViewer.getTable().setSelection(0); + } + return container; + } + + /** + * Handles changes to the list based on changes to the text field. + */ + void handleFilter() { + boolean changed = false; + String newFilter; + if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0) + newFilter = "*"; //$NON-NLS-1$ + changed = fFilter.setPattern(newFilter); + if (changed) { + fAvailableViewer.getTable().setRedraw(false); + fAvailableViewer.refresh(); + fAvailableViewer.getTable().setRedraw(true); + if (fEnabled) { + updateButtonEnablement(false, false); + updateCount(); + } + } + } + + protected Composite createSelectedList(Composite parent) { + Composite container = createViewerContainer(parent, Messages.getString("FilteredListComponent_SelectedListLabel")); //$NON-NLS-1$ + fSelectedViewer = createTableViewer(container, new SelectedContentProvider(), fModelTable.getPreSelected()); + if(fModelTable.getPreSelected().length > 0) { + fSelectedViewer.getTable().setSelection(0); + } + return container; + } + + private Composite createViewerContainer(Composite parent, String message) { + Composite container = new Composite(parent, SWT.NONE); + GridLayout gridLayout = getViewerLayout(); + container.setLayout(gridLayout); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label label = new Label(container, SWT.NONE); + label.setText(message); + return container; + } + + private TableViewer createTableViewer(Composite container, IContentProvider provider, Object[] input) { + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 200; + gd.widthHint = 225; + + Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); + table.setLayoutData(gd); + + TableViewer viewer = new TableViewer(table); + viewer.setLabelProvider(fLabelProvider); + viewer.setContentProvider(provider); + viewer.setInput(input); + viewer.setComparator(new ViewerComparator()); + return viewer; + } + + protected Composite createControlButtonArea(Composite parent) { + ScrolledComposite comp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); + GridLayout layout = new GridLayout(); + layout.marginWidth = layout.marginHeight = 0; + comp.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + Composite container = new Composite(comp, SWT.NONE); + layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginTop = 50; + container.setLayout(layout); + GridData gd = new GridData(GridData.FILL_VERTICAL); + gd.verticalIndent = 15; + container.setLayoutData(gd); + + fAddButton = new Button(container, SWT.PUSH); + fAddButton.setText(Messages.getString("FilteredListComponent_AddButton")); //$NON-NLS-1$ + fAddButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fAddButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAdd(); + } + }); + + fAddAllButton = new Button(container, SWT.PUSH); + fAddAllButton.setText(Messages.getString("FilteredListComponent_AddAllButton")); //$NON-NLS-1$ + fAddAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fAddAllButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAddAll(); + } + }); + + fRemoveButton = new Button(container, SWT.PUSH); + fRemoveButton.setText(Messages.getString("FilteredListComponent_RemoveButton")); //$NON-NLS-1$ + fRemoveButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fRemoveButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemove(); + } + }); + + fRemoveAllButton = new Button(container, SWT.PUSH); + fRemoveAllButton.setText(Messages.getString("FilteredListComponent_RemoveAllButton")); //$NON-NLS-1$ + fRemoveAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fRemoveAllButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveAll(); + } + }); + + fCountLabel = new Label(container, SWT.NONE); + fCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); + comp.setContent(container); + comp.setMinHeight(250); + comp.setExpandHorizontal(true); + comp.setExpandVertical(true); + return container; + } + + private void handleAdd() { + IStructuredSelection ssel = (IStructuredSelection) fAvailableViewer.getSelection(); + if (ssel.size() > 0) { + Table table = fAvailableViewer.getTable(); + int index = table.getSelectionIndices()[0]; + Object[] selection = ssel.toArray(); + setBlockSelectionListeners(true); + setRedraw(false); + for (int i = 0; i < selection.length; i++) { + doAdd(selection[i]); + } + setRedraw(true); + setBlockSelectionListeners(false); + table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); + } + } + + private void handleAddAll() { + ArrayList<Object> data = new ArrayList<Object>(); + for(TableItem item: fAvailableViewer.getTable().getItems()) { + data.add(item.getData()); + } + + if (data.size() > 0) { + Object[] datas = data.toArray(); + setBlockSelectionListeners(true); + setRedraw(false); + for (int i = 0; i < datas.length; i++) { + doAdd(datas[i]); + } + setRedraw(true); + setBlockSelectionListeners(false); + } + } + + private void handleRemove() { + IStructuredSelection ssel = (IStructuredSelection) fSelectedViewer.getSelection(); + if (ssel.size() > 0) { + Table table = fSelectedViewer.getTable(); + int index = table.getSelectionIndices()[0]; + Object[] selection = ssel.toArray(); + setBlockSelectionListeners(true); + setRedraw(false); + for (int i = 0; i < selection.length; i++) { + doRemove(selection[i]); + } + setRedraw(true); + setBlockSelectionListeners(false); + table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); + } + } + + private void doAdd(Object o) { + fModelTable.removeModel(o); + fModelTable.addToPreselected(o); + fSelectedViewer.add(o); + fAvailableViewer.remove(o); + fSelected.put(o, null); + listChanged(true, false); + } + + private void doRemove(Object o) { + fModelTable.addModel(o); + fModelTable.removeFromPreselected(o); + fSelected.remove(o); + fSelectedViewer.remove(o); + fAvailableViewer.add(o); + listChanged(false, true); + } + + private void listChanged(boolean doAddEnablement, boolean doRemoveEnablement) { + updateCount(); + updateButtonEnablement(doAddEnablement, doRemoveEnablement); + fParentPage.setPageComplete(fSelectedViewer.getTable().getItemCount() > 0); + } + + public boolean hasSelectedItems() { + if (fSelectedViewer.getTable().getItems().length > 0) { + return true; + } + return false; + } + + private void handleRemoveAll() { + ArrayList<Object> data = new ArrayList<Object>(); + for(TableItem item: fSelectedViewer.getTable().getItems()) { + data.add(item.getData()); + } + if (data.size() > 0) { + Object[] datas = data.toArray(); + setBlockSelectionListeners(true); + setRedraw(false); + for (int i = 0; i < datas.length; i++) { + doRemove(datas[i]); + } + setRedraw(true); + setBlockSelectionListeners(false); + } + } + + private void setBlockSelectionListeners(boolean blockSelectionListeners) { + fBlockSelectionListeners = blockSelectionListeners; + } + + private void setRedraw(boolean redraw) { + fAvailableViewer.getTable().setRedraw(redraw); + fSelectedViewer.getTable().setRedraw(redraw); + } + + protected void updateCount() { + Integer numAvailable = new Integer(fAvailableViewer.getTable().getItemCount() + fSelectedViewer.getTable().getItemCount()); + Integer numSelected = new Integer(fSelectedViewer.getTable().getItemCount()); + + fCountLabel.setText(numSelected.toString() + " of " + numAvailable.toString() + " selected"); //$NON-NLS-1$ //$NON-NLS-2$ + fCountLabel.getParent().layout(); + } + + protected void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) { + int availableCount = fAvailableViewer.getTable().getItemCount(); + int selectedCount = fSelectedViewer.getTable().getItemCount(); + + fAddAllButton.setEnabled(availableCount > 0); + fRemoveAllButton.setEnabled(selectedCount > 0); + + if(!(availableCount>0) && fAddButton.isEnabled()) { + fAddButton.setEnabled(false); + } + if(!(selectedCount>0) && fRemoveButton.isEnabled()) { + fRemoveButton.setEnabled(false); + } + } + + private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) { + if (available) { + fAddButton.setEnabled(!theSelection.isEmpty()); + } + else { + fRemoveButton.setEnabled(!theSelection.isEmpty()); + } + } + + protected void initialize() { + if (fEnabled) { + updateButtonEnablement(true, true); + } + //setPageComplete(false); + } + + protected void addViewerListeners() { + fAvailableViewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + handleAdd(); + } + }); + + fSelectedViewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + handleRemove(); + } + }); + + fAvailableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (!fBlockSelectionListeners) + updateSelectionBasedEnablement(event.getSelection(), true); + } + }); + + fSelectedViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (!fBlockSelectionListeners) + updateSelectionBasedEnablement(event.getSelection(), false); + } + }); + + fFilterText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + fFilterJob.cancel(); + fFilterJob.schedule(0); + } + }); + } + + public void setEnabled(boolean enabled) { + fFilterText.setEnabled(enabled); + fAddButton.setEnabled(enabled); + fRemoveButton.setEnabled(enabled); + fAddAllButton.setEnabled(enabled); + fRemoveAllButton.setEnabled(enabled); + fAvailableViewer.getControl().setEnabled(enabled); + fSelectedViewer.getControl().setEnabled(enabled); + if (enabled) { + updateButtonEnablement(false, false); + //fParentPage.setPageComplete(fSelectedViewer.getTable().getItemCount() > 0); + } + fEnabled = enabled; + } + + public TableViewer getSelectedViewer() { + return fSelectedViewer; + } + + public Object[] getSelected() { + return fModelTable.getPreSelected(); + } + + public boolean isEnabled() { + return fEnabled; + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackFilterDialog.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackFilterDialog.java new file mode 100644 index 0000000..19493c2 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackFilterDialog.java
@@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.swt.widgets.Shell; + +public class LanguagePackFilterDialog extends FilterDialog { + + public LanguagePackFilterDialog(final Shell parent, final BuildToolWizardConfigurationPage caller) { + super(parent, caller); + + parent.setText(Messages.getString("LanguagePackFilterDialog_Title")); + } + + protected void setChosenFilter(String filter) { + fCallingPage.setLanguagePackFilter(filter); + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackGenerationHandler.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackGenerationHandler.java new file mode 100644 index 0000000..c7eeac0 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LanguagePackGenerationHandler.java
@@ -0,0 +1,247 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.coverage.LanguagePackCoverageReport; +import org.eclipse.babel.build.core.exceptions.FailedDeletionException; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.languagepack.LanguagePack; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.pde.core.plugin.IPluginModelBase; + +public class LanguagePackGenerationHandler { + + private List<File> fSelectedPlugins; + private File fEclipseArchiveLocation; + + private List<String> fSelectedLocales; + + private File fWorkingDirectoryLocation; + private File fTranslationCatalogueLocation; + private Set<String> fExcludeList; + private List<String> fReportFilterPatterns; + private boolean fIncludeXmlReport; + private boolean fLongReport; + + private String fErrorMessage = ""; + + public LanguagePackGenerationHandler(Object[] selectedPlugins, + String[] selectedLocales, + String workingDirectoryLocation, + String translationCataloguelocation, + Object[] ignoreList, + Object[] reportFilterPatterns, + boolean includeXmlReport, + boolean longReport) { + this.fIncludeXmlReport = includeXmlReport; + this.fLongReport = longReport; + this.fSelectedPlugins = new ArrayList<File>(); + getPluginLocations(selectedPlugins); + this.fEclipseArchiveLocation = null; + this.fSelectedLocales = Arrays.asList(selectedLocales); + this.fWorkingDirectoryLocation = new File(workingDirectoryLocation); + this.fTranslationCatalogueLocation = new File(translationCataloguelocation); + + this.fExcludeList = new HashSet<String>(); + for(int i=0; i<ignoreList.length; i++) { + this.fExcludeList.add(ignoreList[i].toString()); + } + + this.fReportFilterPatterns = new ArrayList<String>(); + for(Object pattern : reportFilterPatterns) { + this.fReportFilterPatterns.add(pattern.toString()); + } + } + + public LanguagePackGenerationHandler(String eclipseArchivePath, + String[] selectedLocales, + String workingDirectoryLocation, + String translationCataloguelocation, + Object[] ignoreList, + Object[] reportFilterPatterns, + boolean includeXmlReport, + boolean longReport) { + this.fIncludeXmlReport = includeXmlReport; + this.fLongReport = longReport; + this.fSelectedPlugins = null; + this.fEclipseArchiveLocation = new File(eclipseArchivePath); + this.fSelectedLocales = Arrays.asList(selectedLocales); + this.fWorkingDirectoryLocation = new File(workingDirectoryLocation); + this.fTranslationCatalogueLocation = new File(translationCataloguelocation); + + this.fExcludeList = new HashSet<String>(); + for(int i=0; i<ignoreList.length; i++) { + this.fExcludeList.add(ignoreList[i].toString()); + } + + this.fReportFilterPatterns = new ArrayList<String>(); + for(Object pattern : reportFilterPatterns) { + this.fReportFilterPatterns.add(pattern.toString()); + } + } + + public String generateLanguagePack(IProgressMonitor monitor) { + UserInterfaceConfiguration config; + monitor.beginTask(Messages.getString("LanguagePackGenerationHandler_EclipseParsingTask"), IProgressMonitor.UNKNOWN); + if(fSelectedPlugins == null) { + config = new UserInterfaceConfiguration(fWorkingDirectoryLocation, + fTranslationCatalogueLocation, + fEclipseArchiveLocation, + fSelectedLocales, + fExcludeList, + fReportFilterPatterns, + this, + fIncludeXmlReport, + fLongReport); + } + else { + List<PluginProxy> pluginProxies = getPluginProxies(); + config = new UserInterfaceConfiguration(fWorkingDirectoryLocation, + fTranslationCatalogueLocation, + pluginProxies, + fSelectedLocales, + fExcludeList, + fReportFilterPatterns, + this, + fIncludeXmlReport, + fLongReport); + } + try { + int totalWork = config.eclipseInstall().getPlugins().size() + config.eclipseInstall().getFeatures().size(); + totalWork = totalWork + (int)(totalWork*0.2); + monitor.beginTask(Messages.getString("LanguagePackGenerationHandler_LanguagePackTask"), totalWork); + config.setProgressMonitor(monitor); + + // Generate a language pack + LanguagePack languagePack = new LanguagePack(config); + LanguagePackCoverageReport coverage; + coverage = languagePack.generate(); + + // Create coverage reports + monitor.subTask(Messages.getString("LanguagePackGenerationHandler_CoverageReportTask")); + Configuration.helper.printLanguagePackResult(config, coverage); + monitor.done(); + } catch (InvalidFilenameException f) { + return Messages.getString("Error_InvalidWorkingDirectoryName"); + } catch (FailedDeletionException f) { + return Messages.getString("Error_DeletingWorkingDirectory"); //$NON-NLS-1$ + } + catch (Exception e) { + if (fErrorMessage.equals("")) { + fErrorMessage = Messages.getString("Error_LanguagePack"); + } + return fErrorMessage; + } + return ""; + } + + private void getPluginLocations(Object[] plugins) { + for(Object plugin : plugins) { + String pluginPath = ((IPluginModelBase) plugin).getInstallLocation(); + fSelectedPlugins.add(new File(pluginPath)); + } + } + + private List<PluginProxy> getPluginProxies() { + PluginProxy newPlugin; + List<PluginProxy> plugins = new ArrayList<PluginProxy>(); + for (File plugin: fSelectedPlugins) { + List<ResourceProxy> pluginResources; + if(plugin.isDirectory()) { + pluginResources = extractResources(plugin, plugin.getName()); + newPlugin = new PluginProxy(plugin, pluginResources, false, false); + plugins.add(newPlugin); + } else { + //Handle JAR Plug-in + pluginResources = extractResourcesFromJar(plugin); + newPlugin = new PluginProxy(plugin, pluginResources, true, false); + plugins.add(newPlugin); + } + } + return plugins; + } + + private List<ResourceProxy> extractResources(File file, String pluginName) { + List<ResourceProxy> resources = new LinkedList<ResourceProxy>(); + for (File subFile: file.listFiles()) { + if (subFile.isDirectory()) { + resources.addAll(extractResources(subFile, pluginName)); + } + else { + String absolutePath = subFile.getAbsolutePath(); + String relativePath = absolutePath.substring(absolutePath.indexOf(pluginName)); + relativePath = relativePath.substring(pluginName.length() + 1); + resources.add(new ResourceProxy(subFile, relativePath)); + } + } + return resources; + } + + private List<ResourceProxy> extractResourcesFromJar(File file) { + List<ResourceProxy> jarResources = new LinkedList<ResourceProxy>(); + + try { + JarFile jarPluginOrFeature = new JarFile(file); + + Enumeration<JarEntry> jarEntries = jarPluginOrFeature.entries(); + + JarEntry jarEntry = jarEntries.nextElement(); + while (jarEntry != null) { + String resourceEntryName = jarEntry.getName(); + + if ( isValidResource(resourceEntryName) ) { + jarResources.add(new ResourceProxy( + new File(file.getAbsolutePath() + File.separator + + resourceEntryName), resourceEntryName)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if (jarEntries.hasMoreElements()) { + jarEntry = jarEntries.nextElement(); + } else { + jarEntry = null; + } + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + return jarResources; + } + + private boolean isValidResource(String resourceEntryName) { + for (String exclude : this.fExcludeList) { + if (resourceEntryName.endsWith(exclude)) { + return false; + } + } + return true; + } + + public void notifyError(String errorMessage) { + fErrorMessage = errorMessage; + } + +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/ListFilter.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/ListFilter.java new file mode 100644 index 0000000..5431795 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/ListFilter.java
@@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.Map; +import java.util.regex.Pattern; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +public class ListFilter extends ViewerFilter{ + public static final String WILDCARD = "*"; //$NON-NLS-1$ + private Pattern fPattern; + + private final Map<Object, Object> fSelected; + private final ILabelProvider fLabelProvider; + + public ListFilter(Map<Object, Object> selected, ILabelProvider labelProvider) { + setPattern(WILDCARD); + this.fSelected = selected; + this.fLabelProvider = labelProvider; + } + + public boolean select(Viewer viewer, Object parentElement, Object element) { + // filter out any items that are currently selected + // on a full refresh, these will have been added back to the list + if (fSelected.containsKey(element)) + return false; + + String displayName = fLabelProvider.getText(element); + return matches(element.toString()) || matches(displayName); + } + + private boolean matches(String s) { + return fPattern.matcher(s.toLowerCase()).matches(); + } + + public boolean setPattern(String pattern) { + String newPattern = pattern.toLowerCase(); + + if (!newPattern.endsWith(WILDCARD)) + newPattern += WILDCARD; + if (!newPattern.startsWith(WILDCARD)) + newPattern = WILDCARD + newPattern; + if (fPattern != null) { + String oldPattern = fPattern.pattern(); + if (newPattern.equals(oldPattern)) + return false; + } + fPattern = PatternConstructor.createPattern(newPattern, true); + return true; + } + + private static class PatternConstructor { + private static final Pattern PATTERN_BACK_SLASH = Pattern.compile("\\\\"); //$NON-NLS-1$ + private static final Pattern PATTERN_QUESTION = Pattern.compile("\\?"); //$NON-NLS-1$ + private static final Pattern PATTERN_STAR = Pattern.compile("\\*"); //$NON-NLS-1$ + private static final Pattern PATTERN_LBRACKET = Pattern.compile("\\("); //$NON-NLS-1$ + private static final Pattern PATTERN_RBRACKET = Pattern.compile("\\)"); //$NON-NLS-1$ + + private static String asRegEx(String pattern, boolean group) { + // Replace \ with \\, * with .* and ? with . + // Quote remaining characters + String result1 = PATTERN_BACK_SLASH.matcher(pattern).replaceAll("\\\\E\\\\\\\\\\\\Q"); //$NON-NLS-1$ + String result2 = PATTERN_STAR.matcher(result1).replaceAll("\\\\E.*\\\\Q"); //$NON-NLS-1$ + String result3 = PATTERN_QUESTION.matcher(result2).replaceAll("\\\\E.\\\\Q"); //$NON-NLS-1$ + if (group) { + result3 = PATTERN_LBRACKET.matcher(result3).replaceAll("\\\\E(\\\\Q"); //$NON-NLS-1$ + result3 = PATTERN_RBRACKET.matcher(result3).replaceAll("\\\\E)\\\\Q"); //$NON-NLS-1$ + } + return "\\Q" + result3 + "\\E"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public static Pattern createPattern(String pattern, boolean isCaseSensitive) { + if (isCaseSensitive) + return Pattern.compile(asRegEx(pattern, false)); + return Pattern.compile(asRegEx(pattern, false), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + + public static Pattern createGroupedPattern(String pattern, boolean isCaseSensitive) { + if (isCaseSensitive) + return Pattern.compile(asRegEx(pattern, true)); + return Pattern.compile(asRegEx(pattern, true), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + + private PatternConstructor() { + } + } + +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LocaleLabelProvider.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LocaleLabelProvider.java new file mode 100644 index 0000000..401f80c --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/LocaleLabelProvider.java
@@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.Locale; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class LocaleLabelProvider extends LabelProvider{ + public LocaleLabelProvider() { + } + + @Override + public Image getImage(Object element) { + //return BuildToolImages.LOCALE.createImage(); + return null; + } + + @Override + public String getText(Object element) { + Locale locale = (Locale) element; + String country = locale.getDisplayCountry(); + String varient = locale.getDisplayVariant(); + + return locale.getDisplayLanguage() + " " + getDisplay(country, varient); //$NON-NLS-1$ + } + + private String getDisplay(String country, String varient) { + if("".equals(country)){ + return ""; + } + + if("".equals(varient)){ + return String.format("(%s)", country); + } + return String.format("(%s: %s)", country, varient); + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/Messages.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/Messages.java new file mode 100644 index 0000000..3aca892 --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/Messages.java
@@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages { + private static final String BUNDLE_NAME = "org.eclipse.babel.build.ui.wizard.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/PluginLabelProvider.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/PluginLabelProvider.java new file mode 100644 index 0000000..adff36b --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/PluginLabelProvider.java
@@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class PluginLabelProvider extends LabelProvider{ + + public PluginLabelProvider() { + } + + @Override + public Image getImage(Object element) { + //return BuildToolImages.PLUGIN.createImage(); + return null; + } + + @Override + public String getText(Object element) { + return element == null ? "" : element.toString(); //$NON-NLS-1$ + } +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/UserInterfaceConfiguration.java b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/UserInterfaceConfiguration.java new file mode 100644 index 0000000..758ee3b --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/UserInterfaceConfiguration.java
@@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2001, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.babel.build.ui.wizard; + +import java.io.File; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.babel.build.core.Configuration; +import org.eclipse.babel.build.core.Filter; +import org.eclipse.babel.build.core.LocaleGroup; +import org.eclipse.babel.build.core.LocaleProxy; +import org.eclipse.babel.build.core.PluginProxy; +import org.eclipse.babel.build.core.Range; +import org.eclipse.babel.build.core.ResourceProxy; +import org.eclipse.babel.build.core.eclipsetarget.EclipseTarget; +import org.eclipse.babel.build.core.exceptions.InvalidFilenameException; +import org.eclipse.babel.build.core.exceptions.InvalidLocationException; +import org.eclipse.babel.build.core.exceptions.MissingLocationException; +import org.eclipse.babel.build.core.translationcatalogue.TranslationCatalogue; + +public class UserInterfaceConfiguration implements Configuration { + + private IProgressMonitor fMonitor; + + private final File fWorkingDirectory; + private final File fEclipseRoot; + private final File fTranslationsRoot; + + private EclipseTarget fEclipseTarget = null; + private TranslationCatalogue fTranslationCatalogue = null; + + private final List<PluginProxy> fPluginProxies; + private final Set<LocaleProxy> fLocales; + private final Set<LocaleGroup> fLocaleGroups; + private final Set<String> fExcludeList; + private List<Filter> fReportFilters; + private File fReport; + private final LanguagePackGenerationHandler fParentHandler; + private final boolean fIncludeXmlReport; + private final boolean fLongReport; + private String fLocaleExtension; + + + public UserInterfaceConfiguration(File workingDirectoryPath, + File translationCatalogueLocation, + File eclipseArchiveLocation, + List<String> locales, + Set<String> excludeList, + List<String> reportFilterPatterns, + LanguagePackGenerationHandler parentHandler, + boolean includeXmlReport, + boolean longReport) { + this.fIncludeXmlReport = includeXmlReport; + this.fLongReport = longReport; + this.fParentHandler = parentHandler; + this.fWorkingDirectory = workingDirectoryPath; + this.fEclipseRoot = eclipseArchiveLocation; + this.fTranslationsRoot = translationCatalogueLocation; + this.fPluginProxies = null; + + this.fLocales = getLocaleProxies(locales); + this.fLocaleGroups = getLocaleGroups(locales); + + this.fExcludeList = excludeList; + this.fReport = new File(fWorkingDirectory, "coverage.xml"); + this.fReportFilters = buildFilterList(reportFilterPatterns); + eclipseInstall(); + + fLocaleExtension = ""; + if (this.fLocales.size() == 1 && this.fLocaleGroups.isEmpty()) { + LocaleProxy singleLocale = this.fLocales.iterator().next(); + fLocaleExtension += Messages.getString("Characters_Underscore") + singleLocale.getName(); //$NON-NLS-1$ + } + } + + public UserInterfaceConfiguration(File workingDirectoryPath, + File translationCatalogueLocation, + List<PluginProxy> pluginProxies, + List<String> locales, + Set<String> excludeList, + List<String> reportFilterPatterns, + LanguagePackGenerationHandler parentHandler, + boolean includeXmlReport, + boolean longReport) { + this.fIncludeXmlReport = includeXmlReport; + this.fLongReport = longReport; + this.fParentHandler = parentHandler; + this.fWorkingDirectory = workingDirectoryPath; + this.fEclipseRoot = null; + this.fTranslationsRoot = translationCatalogueLocation; + this.fPluginProxies = pluginProxies; + + this.fLocales = getLocaleProxies(locales); + this.fLocaleGroups = getLocaleGroups(locales); + + this.fExcludeList = excludeList; + this.fReport = new File(fWorkingDirectory, "coverage.xml"); + this.fReportFilters = buildFilterList(reportFilterPatterns); + eclipseInstall(); + + fLocaleExtension = ""; + if (this.fLocales.size() == 1 && this.fLocaleGroups.isEmpty()) { + LocaleProxy singleLocale = this.fLocales.iterator().next(); + fLocaleExtension += Messages.getString("Characters_Underscore") + singleLocale.getName(); //$NON-NLS-1$ + } + } + + private List<Filter> buildFilterList(List<String> filterPatterns){ + List<Filter> filters = new LinkedList<Filter>(); + for(String pattern : filterPatterns){ + filters.add(new Filter(pattern)); + } + return filters; + } + + private static Set<LocaleProxy> getLocaleProxies(List<String> localeNames){ + Set<LocaleProxy> locales = new HashSet<LocaleProxy>(); + for(String localeName : localeNames){ + if (! LocaleGroup.isValidGroupName(localeName) && !LocaleGroup.isValidGroupFullName(localeName)){ + locales.add(new LocaleProxy(localeName)); + } + } + + return locales; + } + + private static Set<LocaleGroup> getLocaleGroups(List<String> locales){ + Set<LocaleGroup> set = new HashSet<LocaleGroup>(); + for(String localeName : locales){ + if (LocaleGroup.isValidGroupName(localeName)) { + set.add(LocaleGroup.get(localeName)); + } + else if(LocaleGroup.isValidGroupFullName(localeName)) { + set.add(LocaleGroup.getByFullName(localeName)); + } + } + return set; + } + + public Range compatibilityRange() { + // TODO Auto-generated method stub + return null; + } + + public EclipseTarget eclipseInstall() { + try { + if (fEclipseTarget == null){ + if(fEclipseRoot == null) { + fEclipseTarget = new EclipseTarget(fPluginProxies); + } + else { + fEclipseTarget = new EclipseTarget(fEclipseRoot, fExcludeList); + fEclipseTarget.populatePlugins(); + } + } + } catch (InvalidLocationException i) { + fParentHandler.notifyError(Messages.getString("Error_InvalidEclipseTarget") + Messages.getString("Error_EclipseEntryLocation") + fEclipseRoot); //$NON-NLS-1$ + return null; + } catch (MissingLocationException m) { + fParentHandler.notifyError(Messages.getString("Error_MissingEclipseTarget") + Messages.getString("Error_EclipseEntryLocation") + fEclipseRoot); //$NON-NLS-1$ + return null; + } catch(InvalidFilenameException f) { + fParentHandler.notifyError(Messages.getString("Error_InvalidEclipseTargetName") + Messages.getString("Error_EclipseEntryLocation") + fEclipseRoot); //$NON-NLS-1$ + return null; + } catch (Exception e) { + fParentHandler.notifyError(Messages.getString("Error_EclipseTarget") + Messages.getString("Error_EclipseEntryLocation") + fEclipseRoot ); //$NON-NLS-1$ + return null; + } + return fEclipseTarget; + } + + public Set<String> excludeList() { + return fExcludeList; + } + + public List<Filter> filters() { + // TODO Auto-generated method stub + return null; + } + + public boolean includePseudoTranslations() { + // TODO Auto-generated method stub + return false; + } + + public Set<LocaleGroup> localeGroups() { + return fLocaleGroups; + } + + public Set<LocaleProxy> locales() { + return fLocales; + } + + public File reportLocation() { + return fReport; + } + + public Date timestamp() { + // TODO Auto-generated method stub + return null; + } + + public TranslationCatalogue translations() { + if (fTranslationCatalogue == null){ + try { + + if (fLocaleGroups.isEmpty()) { + fTranslationCatalogue = new TranslationCatalogue(fTranslationsRoot, fLocales); + } else { + fLocales.clear(); + fTranslationCatalogue = new TranslationCatalogue(fTranslationsRoot, fLocaleGroups); + fLocales.addAll(fTranslationCatalogue.getAllLocales()); + } + + } catch (MissingLocationException m) { + fParentHandler.notifyError(Messages.getString("Error_MissingTranslationCatalogue") + Messages.getString("Error_TranslationsEntryLocation") + fTranslationsRoot); //$NON-NLS-1$ + return null; + } catch (InvalidLocationException i) { + fParentHandler.notifyError(i.getMessage()); + return null; + } catch(InvalidFilenameException f) { + fParentHandler.notifyError(Messages.getString("Error_InvalidTranslationCatalogueName") + Messages.getString("Error_TranslationsEntryLocation") + fTranslationsRoot); //$NON-NLS-1$ + return null; + } + } + return fTranslationCatalogue; + } + + public File workingDirectory() { + return fWorkingDirectory; + } + + public boolean includeResource(PluginProxy plugin, ResourceProxy resource) { + for(Filter filter : fReportFilters){ + if(filter.matches(plugin, resource)){ + return filter.isInclusive(); + } + } + return true; + } + + public void setProgressMonitor(IProgressMonitor monitor) { + this.fMonitor = monitor; + } + + public void notifyProgress(String fragmentName) { + fMonitor.subTask("Generating fragment for " + fragmentName); + fMonitor.worked(1); + } + + public boolean includeXmlReport() { + return fIncludeXmlReport; + } + + public boolean longReport() { + return fLongReport; + } + + public String localeExtension() { + return fLocaleExtension; + } + +}
diff --git a/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/messages.properties b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/messages.properties new file mode 100644 index 0000000..306256a --- /dev/null +++ b/org.eclipse.babel.build.ui/src/org/eclipse/babel/build/ui/wizard/messages.properties
@@ -0,0 +1,84 @@ +############################################################################### +# Copyright (c) 2001, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +BuildToolWizardPluginPage_PageTitle=Select Plug-ins +BuildToolWizardPluginPage_PageDescription=Select plug-ins for which a language pack should be generated. +BuildToolWizardPluginPage_GenerateFromArchiveLabel=&Generate from external Eclipse archive +BuildToolWizardPluginPage_ExternalArchiveLocationLabel=Location of Eclipse arch&ive: +BuildToolWizardPluginPage_SelectEclipseArchiveDialogTitle=Select External Eclipse Archive +BuildToolWizardPluginPage_BrowseButton=Bro&wse... + +BuildToolWizardLocalePage_PageTitle=Select Locales +BuildToolWizardLocalePage_PageDescription=Select locales for which a language pack should be generated. +BuildToolWizardLocalePage_GenerateForLocaleGroupLabel=&Generate language pack for locale group +BuildToolWizardLocalePage_LocaleGroupLabel=&Locale group: +BuildToolWizardLocalePage_AllLocaleCheckbox=Generate language pack for all locales in my translation catalogue + +BuildToolWizardConfigurationPage_PageTitle=Configuration +BuildToolWizardConfigurationPage_PageDescription=Provide additional information needed for language pack generation. +BuildToolWizardConfigurationPage_GenerateLongReportLabel=Generate a full coverage &report +BuildToolWizardConfigurationPage_GenerateXMLReportLabel=Generate an &XML coverage report +BuildToolWizardConfigurationPage_TranslationCatalogueLabel=Location of translation &catalogue: +BuildToolWizardConfigurationPage_TranslationCatalogueDialogTitle=Select Translation Catalogue Location +BuildToolWizardConfigurationPage_TranslationCatalogueDialogMessage=Please select the translation catalogue folder. If generating for locales, make sure to have the locale folders directly under this directory, otherwise, the group folders. +BuildToolWizardConfigurationPage_TranslationCatalogueBrowseButton=Bro&wse... +BuildToolWizardConfigurationPage_WorkingDirectoryLabel=Location of wor&king directory: +BuildToolWizardConfigurationPage_WorkingDirectoryDialogTitle=Select Working Directory +BuildToolWizardConfigurationPage_WorkingDirectoryDialogMessage=Please choose a working directory into which the language pack and coverage reports will be generated. +BuildToolWizardConfigurationPage_WorkingDirectoryBrowseButton=B&rowse... +BuildToolWizardConfigurationPage_IgnoreListLabel=Plug-in/Resource patterns to ignore when generating a language &pack: +BuildToolWizardConfigurationPage_FilterListLabel=Plug-in/Reso&urce patterns to ignore when generating a coverage report: +BuildToolWizardConfigurationPage_AddLanguagePackFilterButton=&Add Filter... +BuildToolWizardConfigurationPage_RemoveLanguagePackFilterButton=Re&move Filter +BuildToolWizardConfigurationPage_SelectAllLanguagePackFiltersButton=Se&lect All +BuildToolWizardConfigurationPage_DeselectAllLanguagePackFiltersButton=D&eselect All +BuildToolWizardConfigurationPage_AddCoverageReportFilterButton=Add &Filter... +BuildToolWizardConfigurationPage_RemoveCoverageReportFilterButton=Remo&ve Filter +BuildToolWizardConfigurationPage_SelectAllCoverageReportFiltersButton=&Select All +BuildToolWizardConfigurationPage_DeselectAllCoverageReportFiltersButton=&Deselect All + +FilteredListComponent_FilterAvailableListLabel=Fil&ter available list: +FilteredListComponent_FilterDescriptionLabel=ID (* = any string, ? = any character): +FilteredListComponent_AvailableListLabel=&Found: +FilteredListComponent_SelectedListLabel=&Selected: +FilteredListComponent_AddButton=&Add --> +FilteredListComponent_AddAllButton=A&dd All --> +FilteredListComponent_RemoveButton=<-- &Remove +FilteredListComponent_RemoveAllButton=<-- Re&move All + +CoverageReportFilterDialog_Title=Add Coverage Report Filter +LanguagePackFilterDialog_Title=Add Language Pack Filter + +FilterDialog_EnterPatternLabel=Enter a filter to be added: +FilterDialog_PatternValidationError=Invalid regular expression. + +LanguagePackGenerationHandler_EclipseParsingTask=Parsing Eclipse install +LanguagePackGenerationHandler_CoverageReportTask=Generating coverage reports +LanguagePackGenerationHandler_LanguagePackTask=Generating language pack + +Error_EclipseTarget=Error parsing eclipse target. +Error_MissingEclipseTarget=Error parsing eclipse target. Please verify that the specified target exists at the given location. +Error_InvalidEclipseTarget=Error parsing eclipse target. Please verify that the specified target is a valid eclipse target with the proper directory structure. +Error_InvalidEclipseTargetName=Error parsing eclipse target. Please verify that the specified target path is structured properly and is absolute. +Error_InvalidTranslationCatalogue=Error parsing translation catalogue. If generating for locales, please verify that the specified translation catalogue location holds the locale folders. If generating for language groups, please verify that the specified translation catalogue location holds the language group folders. +Error_MissingTranslationCatalogue=Error parsing translation catalogue. Please verify that the translation catalogue exists at the given location. +Error_InvalidTranslationCatalogueName=Error parsing translation catalogue. Please verify that the translation catalogue path is structured properly and is absolute. +Error_InvalidWorkingDirectoryName=Error generating language pack. Please verify that the specified working directory path is structured properly and is absolute. +Error_LanguagePack=Error generating language pack. +Error_TranslationsEntryLocation=\n The specified translation catalogue location was: +Error_EclipseEntryLocation=\n The specified eclipse archive location was: +Error_DeletingWorkingDirectory=Error clearing the eclipse folder in the work directory. Please clear the eclipse folder before proceeding with another run. + +Characters_Underscore=_ + +Common_AddButton=&Add +Common_CancelButton=&Cancel + +Wizard_Title=Export \ No newline at end of file