[org-vaadin-support~subversion:27] Add the downloaded GWT Jars to the classpath of the project.
- From: GWiel@kenai.com
- To: commits@org-vaadin-support.kenai.com
- Subject: [org-vaadin-support~subversion:27] Add the downloaded GWT Jars to the classpath of the project.
- Date: Sun, 17 Oct 2010 23:15:05 +0000
Project: org-vaadin-support
Repository: subversion
Revision: 27
Author: GWiel
Date: 2010-10-17 23:15:02 UTC
Link:
Log Message:
------------
Add the downloaded GWT Jars to the classpath of the project.
Revisions:
----------
27
Modified Paths:
---------------
VaadinFramework/src/org/vaadin/framework/VaadinConfigurationPanelVisual.java
VaadinFramework/src/org/vaadin/framework/VaadinConfigUtilities.java
VaadinFramework/src/org/vaadin/framework/VaadinFrameworkProvider.java
Diffs:
------
Index: VaadinFramework/src/org/vaadin/framework/VaadinConfigUtilities.java
===================================================================
--- VaadinFramework/src/org/vaadin/framework/VaadinConfigUtilities.java
(revision 26)
+++ VaadinFramework/src/org/vaadin/framework/VaadinConfigUtilities.java
(revision 27)
@@ -10,15 +10,21 @@
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
* Microsystems, Inc. All Rights Reserved.
*/
-
package org.vaadin.framework;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
+import javax.swing.JOptionPane;
+import org.apache.commons.io.IOUtils;
+import org.netbeans.api.project.libraries.Library;
import org.netbeans.api.project.libraries.LibraryManager;
import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
@@ -29,63 +35,65 @@
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
/**
*
* @author Petr Pisl
*/
public class VaadinConfigUtilities {
-
- private static final String LIB_FOLDER = "VaadinDownloads"; //NOI18N
- public static Servlet getVaadinServlet(FileObject dd){
+ //private static final String LIB_FOLDER = "VaadinDownloads"; //NOI18N
+ public static Servlet getVaadinServlet(FileObject dd) {
- if (dd == null) {
+ if (dd == null) {
return null;
}
- try {
+ try {
WebApp webApp = DDProvider.getDefault().getDDRoot(dd);
- return (Servlet) webApp
- .findBeanByName("Servlet", "ServletClass",
"com.vaadin.terminal.gwt.server.ApplicationServlet"); //NOI18N;
+ return (Servlet) webApp.findBeanByName("Servlet",
"ServletClass", "com.vaadin.terminal.gwt.server.ApplicationServlet");
//NOI18N;
} catch (java.io.IOException e) {
return null;
}
}
- public static String getVaadinFilterMapping(FileObject dd){
+ public static String getVaadinFilterMapping(FileObject dd) {
Servlet filter = getVaadinServlet(dd);
- if (filter != null){
- try{
+ if (filter != null) {
+ try {
WebApp webApp = DDProvider.getDefault().getDDRoot(dd);
FilterMapping[] mappings = webApp.getFilterMapping();
- for (int i = 0; i < mappings.length; i++){
- if
(mappings[i].getFilterName().equals(filter.getServletName()))
+ for (int i = 0; i < mappings.length; i++) {
+ if
(mappings[i].getFilterName().equals(filter.getServletName())) {
return mappings[i].getUrlPattern();
+ }
}
} catch (java.io.IOException e) {
-
}
}
return null;
}
-
- public static boolean createVaadinUserLibrary(final String libraryName)
throws IOException {
+
+ public static boolean createVaadinUserLibrary(String folder, final
String libraryName) throws IOException {
boolean result = false;
-
+
// find all jars in the folder/lib
- FileObject vaadinFolder = FileUtil.getConfigFile(LIB_FOLDER);
-
- File libFolder = FileUtil.toFile(vaadinFolder);
+ FileObject folderFo = FileUtil.getConfigFile(folder);
+
+ File libFolder = FileUtil.toFile(folderFo);
+
if (libFolder.exists() && libFolder.isDirectory()) {
- File[] jars = libFolder.listFiles( new FileFilter () {
+
+ File[] jars = libFolder.listFiles(new FileFilter() {
+
public boolean accept(File pathname) {
return pathname.getName().contains(libraryName); //NOI18N
}
});
// obtain URLs of the jar file
- List <URL> urls = new ArrayList <URL> ();
+ List<URL> urls = new ArrayList<URL>();
for (int i = 0; i < jars.length; i++) {
URL url = FileUtil.urlForArchiveOrDir(jars[i]);
if (url != null) {
@@ -93,19 +101,60 @@
}
}
- // create new library and register in the Library Manager.
+ // create new library and register in the Library Manager,
+ // if it doesn't exist already.
LibraryManager libraryManager = LibraryManager.getDefault();
- LibraryImplementation libImpl =
LibrariesSupport.getLibraryTypeProvider("j2se").createLibrary(); //NOI18N
- libImpl.setName(libraryName); //NOI18N
- libImpl.setDescription(libraryName);
- libImpl.setContent("classpath", urls); //NOI18N
- libraryManager.addLibrary(LibraryFactory.createLibrary(libImpl));
-
+ if (LibraryManager.getDefault().getLibrary(libraryName) == null)
{
+ LibraryImplementation libImpl =
LibrariesSupport.getLibraryTypeProvider("j2se").createLibrary(); //NOI18N
+ libImpl.setName(libraryName); //NOI18N
+ libImpl.setDescription(libraryName);
+ libImpl.setContent("classpath", urls); //NOI18N
+
libraryManager.addLibrary(LibraryFactory.createLibrary(libImpl));
+ }
result = true;
}
-
+
return result;
-
+
}
+ public static String getRelatedGWTVersion(File vaadinFile) {
+ String gwtVersion = null;
+ FileObject downloadedVaadinJAR =
FileUtil.getArchiveRoot(FileUtil.toFileObject(vaadinFile));
+ //Get the children of the ODP file (i.e., the content):
+ FileObject[] archiveKids = downloadedVaadinJAR.getChildren();
+ //Iterate through the content
+ for (FileObject oneArchiveKid : archiveKids) {
+ //Take the child called "META-INF":
+ if (oneArchiveKid.getName().equals("META-INF")) {
+ //Iterate through the content of the "meta-inf" folder:
+ FileObject[] metaInfKids = oneArchiveKid.getChildren();
+ for (FileObject oneMetaInfKid : metaInfKids) {
+ if (oneMetaInfKid.getName().equals("MANIFEST")) {
+ Properties manifestProps = new Properties();
+ try {
+
manifestProps.load(oneMetaInfKid.getInputStream());
+ if (manifestProps.getProperty("GWT-Version") !=
null) {
+ gwtVersion =
manifestProps.getProperty("GWT-Version");
+ } else {
+ //Here we failed to find GWT-VERSION in the
manifest,
+ //so we do it the old way, by looking in the
GWT-VERSION file:
+ for (FileObject anotherOneMetaInfKid :
metaInfKids) {
+ if
(anotherOneMetaInfKid.getName().equals("GWT-VERSION")) {
+ InputStream stream =
anotherOneMetaInfKid.getInputStream();
+ StringWriter writer = new
StringWriter();
+ IOUtils.copy(stream, writer);
+ gwtVersion = writer.toString();
+ }
+ }
+ }
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
+ }
+ }
+ }
+ return gwtVersion;
+ }
}
Index: VaadinFramework/src/org/vaadin/framework/VaadinFrameworkProvider.java
===================================================================
--- VaadinFramework/src/org/vaadin/framework/VaadinFrameworkProvider.java
(revision 26)
+++ VaadinFramework/src/org/vaadin/framework/VaadinFrameworkProvider.java
(revision 27)
@@ -1,17 +1,10 @@
/*
-
* VaadinFrameworkProvider.java
-
*
-
* Created on March 13, 2006, 1:36 PM
-
*
-
* To change this template, choose Tools | Template Manager
-
* and open the template in the editor.
-
*/
package org.vaadin.framework;
@@ -57,6 +50,7 @@
import java.util.Date;
import java.util.Set;
+import javax.swing.JOptionPane;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.project.classpath.ProjectClassPathModifier;
import org.netbeans.modules.j2ee.dd.api.web.WelcomeFileList;
@@ -87,14 +81,31 @@
public Set extendImpl(WebModule webModule) throws IOException {
String libraryName = extender.getSelectedVaadinJar();
- VaadinConfigUtilities.createVaadinUserLibrary(libraryName);
+ VaadinConfigUtilities.createVaadinUserLibrary("VaadinDownloads",
libraryName);
Library vaadinLibrary =
LibraryManager.getDefault().getLibrary(libraryName);
+ Library[] gwtLibraries = null;
- FileObject fo = webModule.getDocumentBase();
+ FileObject vaadinDownloadsFolder =
FileUtil.getConfigFile("VaadinDownloads");
+ FileObject[] vaadinJars = vaadinDownloadsFolder.getChildren();
+ for (FileObject vaadinJar : vaadinJars) {
+ if (vaadinJar.getNameExt().equals(libraryName)) {
+ File vaadinFile = FileUtil.toFile(vaadinJar);
+ String gwtVersion =
VaadinConfigUtilities.getRelatedGWTVersion(vaadinFile);
+ FileObject vaadinVersionedSupportDownloadsFolder =
FileUtil.getConfigFile("VaadinSupportDownloads/" + gwtVersion);
+ FileObject[] gwtJars =
vaadinVersionedSupportDownloadsFolder.getChildren();
+ gwtLibraries = new Library[gwtJars.length];
+ for (int i = 0; i < gwtJars.length; i++) {
+
VaadinConfigUtilities.createVaadinUserLibrary("VaadinSupportDownloads/" +
gwtVersion, gwtJars[i].getName());
+ gwtLibraries[i] =
LibraryManager.getDefault().getLibrary(gwtJars[i].getName());
+ }
+ }
+ }
+
FileObject[] javaSources = webModule.getJavaSources();
if (vaadinLibrary != null && javaSources.length > 0) {
ProjectClassPathModifier.addLibraries(new
Library[]{vaadinLibrary}, javaSources[0], ClassPath.COMPILE);
+ ProjectClassPathModifier.addLibraries(gwtLibraries,
javaSources[0], ClassPath.COMPILE);
try {
FileSystem fs = webModule.getWebInf().getFileSystem();
fs.runAtomicAction(new CreateVaadinFiles(webModule));
@@ -265,14 +276,14 @@
vaadinApplication = formater.format(vaadinApplication);
vaadinExampleUtils = formater.format(vaadinExampleUtils);
-
+
Project project =
FileOwnerQuery.getOwner(wm.getDocumentBase());
//Create the build-widgetset.xml in the root directory:
FileObject projDirectory = project.getProjectDirectory();
FileObject buildWidgetFO =
FileUtil.createData(projDirectory, "build-widgetset.xml"); //NOI18N
createFile(buildWidgetFO, buildWidgetset, "UTF-8"); //NOI18N
-
+
SourceGroup[] sourceGroups =
ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
String path = extender.getPkgResource();
String name = extender.getAppResource();
Index:
VaadinFramework/src/org/vaadin/framework/VaadinConfigurationPanelVisual.java
===================================================================
---
VaadinFramework/src/org/vaadin/framework/VaadinConfigurationPanelVisual.java
(revision 26)
+++
VaadinFramework/src/org/vaadin/framework/VaadinConfigurationPanelVisual.java
(revision 27)
@@ -14,17 +14,12 @@
import java.awt.Dialog;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Properties;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -295,9 +290,6 @@
File vaadinFile = FileUtil.toFile(vaadinJAR);
Thread downloadThread = new Thread(new
DownloadVaadinRunnable(versionURL, vaadinFile));
downloadThread.start();
-
-
-
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
@@ -333,7 +325,7 @@
jListVersion.setSelectedValue(vaadinFile.getName(), true);
//Download the related GWT User and Dev jars:
- String gwtVersion = getRelatedGWTVersion(vaadinFile);
+ String gwtVersion =
VaadinConfigUtilities.getRelatedGWTVersion(vaadinFile);
URL gwtUserURL;
URL gwtDevURL;
try {
@@ -414,46 +406,7 @@
return inputStream;
}
- private String getRelatedGWTVersion(File vaadinFile) {
- String gwtVersion = null;
- FileObject downloadedVaadinJAR =
FileUtil.getArchiveRoot(FileUtil.toFileObject(vaadinFile));
- //Get the children of the ODP file (i.e., the content):
- FileObject[] archiveKids = downloadedVaadinJAR.getChildren();
- //Iterate through the content
- for (FileObject oneArchiveKid : archiveKids) {
- //Take the child called "META-INF":
- if (oneArchiveKid.getName().equals("META-INF")) {
- //Iterate through the content of the "meta-inf" folder:
- FileObject[] metaInfKids = oneArchiveKid.getChildren();
- for (FileObject oneMetaInfKid : metaInfKids) {
- if (oneMetaInfKid.getName().equals("MANIFEST")) {
- Properties manifestProps = new Properties();
- try {
-
manifestProps.load(oneMetaInfKid.getInputStream());
- if (manifestProps.getProperty("GWT-Version") !=
null) {
- gwtVersion =
manifestProps.getProperty("GWT-Version");
- } else {
- //Here we failed to find GWT-VERSION in the
manifest,
- //so we do it the old way, by looking in the
GWT-VERSION file:
- for (FileObject anotherOneMetaInfKid :
metaInfKids) {
- if
(anotherOneMetaInfKid.getName().equals("GWT-VERSION")) {
- InputStream stream =
anotherOneMetaInfKid.getInputStream();
- StringWriter writer = new
StringWriter();
- IOUtils.copy(stream, writer);
- gwtVersion = writer.toString();
- }
- }
- }
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- }
- }
- }
- return gwtVersion;
- }
-
+
// private void checkFolderInstallation() {
// File folder = new File(jtFolder.getText());
// if (!VaadinConfigUtilities.isVaadinInstallFolder(folder)) {
|
[org-vaadin-support~subversion:27] Add the downloaded GWT Jars to the classpath of the project. |
GWiel | 10/17/2010 |





