Package de.innovationgate.eclipse.wgadesigner.classpath

Source Code of de.innovationgate.eclipse.wgadesigner.classpath.WGADeploymentLibrarySet

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.classpath;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;

import de.innovationgate.eclipse.utils.BeanMapPreferencesStore;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeployment;
import de.innovationgate.wga.common.beans.csconfig.v1.Version;

public class WGADeploymentLibrarySet implements LibrarySet {
 
  private WGADeployment _deployment;
 
  private static final Map<String, IPath> jarToProjectSource = new HashMap<String, IPath>();
 
  static {
    jarToProjectSource.put("tmlscript.jar", new Path("/TMLScript/src"));
    jarToProjectSource.put("wgapi.jar", new Path("/WGAPI"));
    jarToProjectSource.put("wgapi_jdbc.jar", new Path("/WGAPI_JDBC"));
    jarToProjectSource.put("wgaservicesclient.jar", new Path("/WGAServicesClient/src"));
    jarToProjectSource.put("wgutils.jar", new Path("/WGUtils"));
  }

  public WGADeploymentLibrarySet(WGADeployment deployment) {
    _deployment = deployment;
  }

  public IClasspathEntry[] getClasspathEntries() {
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
   
    File libDir = new File(_deployment.getDeployDir(), "WEB-INF/lib");
    File classesDir = new File(_deployment.getDeployDir(), "WEB-INF/classes");
    File isolatedDir = new File(_deployment.getDeployDir(), "WEB-INF/isolated");
    if (!_deployment.isWorkspaceDeployment()) {     
      entries.addAll(DirectoryLibrarySet.retrieveClasspathEntries(libDir));          
      entries.add(JavaCore.newLibraryEntry(new Path(classesDir.getAbsolutePath()) , new Path(""), null));         
      entries.addAll(DirectoryLibrarySet.retrieveClasspathEntries(isolatedDir));
    } else {
      entries.addAll(retrieveClasspathEntries(libDir));
      BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation> store = WGADesignerPlugin.getDefault().getLibraryClasspathEntryInformationStore();
      store.load();
      if (!store.getBeans().containsKey(new Path(classesDir.getAbsolutePath()))) {
        LibraryClasspathEntryInformation info = new LibraryClasspathEntryInformation();
        info.setSourcePath(new Path("/WGAPublisher/JavaSource"));
        store.getBeans().put(new Path(classesDir.getAbsolutePath()), info);
        store.flush();
      }     
      entries.add(JavaCore.newLibraryEntry(new Path(classesDir.getAbsolutePath()) , null, null));   
      entries.addAll(retrieveClasspathEntries(isolatedDir));     
    }
   
    return entries.toArray(new IClasspathEntry[0]);
  }

  private List<IClasspathEntry> retrieveClasspathEntries(File directory) {
    List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>();

    File[] libs = directory.listFiles(new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith(".jar");
      }     
    });
    if (libs != null) {         
      BeanMapPreferencesStore<IPath, LibraryClasspathEntryInformation> store = WGADesignerPlugin.getDefault().getLibraryClasspathEntryInformationStore();
      store.load();
      Map<IPath, LibraryClasspathEntryInformation> infos = store.getBeans();
      for( File lib: libs ) {
        IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(lib.getAbsolutePath()), null, null);
        IPath srcPath = jarToProjectSource.get(lib.getName());
        if (srcPath != null) {
          if (!infos.containsKey(new Path(lib.getAbsolutePath()))) {
            LibraryClasspathEntryInformation info = new LibraryClasspathEntryInformation();
            info.setSourcePath(srcPath);
            store.getBeans().put(entry.getPath(), info);
          }
        }
          entryList.add(entry);
      }
      store.flush();
    }
    return entryList;
  }

  public String getId() {
    return "WGADeployment_" + _deployment.getName();
  }

  public String getName() {
    return "Deployment [" + _deployment.getName() + "]";
  }

  public String[] getDependencies() {
    Version version = _deployment.getWGAVersion();
    if (version != null) {
      if (version.isAtLeast(5, 0)) {
        return new String[] {WGADesignerPlugin.LIBRARY_SET_J2EE_1_4};
      } else if (version.isAtLeast(4, 1)) {
        return new String[] {WGADesignerPlugin.LIBRARY_SET_J2EE_1_4};
      } else if (version.isAtLeast(4, 0)) {
        return new String[] {WGADesignerPlugin.LIBRARY_SET_J2EE_1_4};
      } else if (version.isAtLeast(3, 3)) {
        return new String[] {WGADesignerPlugin.LIBRARY_SET_J2EE_1_3};
      }
    }   
    return null;
  }

 
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.classpath.WGADeploymentLibrarySet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.