Update of /cvsroot/metamorphosis/ruper2/src/java/eclipse/org/krysalis/ruper2/eclipse
In directory sc8-pr-cvs1:/tmp/cvs-serv24940/src/java/eclipse/org/krysalis/ruper2/eclipse
Added Files:
EclipseFileUpdater.java
Log Message:
Eclipse API
--- NEW FILE: EclipseFileUpdater.java ---
/*
* Created on Oct 6, 2003
*/
package org.krysalis.ruper2.eclipse;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IResource;
import org.krysalis.ruper2.ResourceUpdater;
import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.eclipse.util.RuperEclipseHelper;
import org.krysalis.ruper2.files.DefaultResourceFilenameAnalyzer;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.repository.Repository;
import org.krysalis.ruper2.resource.Resource;
/**
* @author anou_mana
*/
public class EclipseFileUpdater {
private RuperEclipseHelper m_ruperEclipseHelper;
private ResourceUpdater m_ruper;
DefaultResourceFilenameAnalyzer m_fileNameAnalyzer;
/**
*
*/
public EclipseFileUpdater() throws RuperException {
super();
m_ruperEclipseHelper = new RuperEclipseHelper();
m_fileNameAnalyzer =
new DefaultResourceFilenameAnalyzer(
new VirtualResourceLocator(
m_ruperEclipseHelper.getEclipsePathStr()));
}
public void updateFiles(List files) throws RuperException {
for (Iterator iterator = files.iterator(); iterator.hasNext();) {
updateFile((File) iterator.next());
}
}
public void updateFile(File file) throws RuperException {
List resources = getResourceList(file, true);
if (resources != null)
m_ruper.updateResources(resources);
}
public void updateFile(String baseDir, String fileName)
throws RuperException {
Resource resource = getResource(baseDir, fileName, true);
if (resource != null) {
// update the resource
m_ruper.updateResource(resource);
}
}
public void updateFiles(String baseDir, List fileNames)
throws RuperException {
for(Iterator iterator = fileNames.iterator(); iterator.hasNext();){
updateFile(baseDir, (String)iterator.next());
}
}
public void downloadFile(String baseDir, String fileName)
throws RuperException {
Resource resource = getResource(baseDir, fileName, true);
if (resource != null) {
// update the resource
m_ruper.updateResource(resource);
}
}
public void downloadFiles(String baseDir, List fileNames)
throws RuperException {
for(Iterator iterator = fileNames.iterator(); iterator.hasNext();){
downloadFile(baseDir, (String)iterator.next());
}
}
/*
* Finds files and returns resources
*/
public Map findResource(File file) throws RuperException {
Map foundFiles = null;
List resources = getResourceList(file, false);
if (resources != null)
foundFiles = m_ruper.findResources(resources);
return foundFiles;
}
public void downloadResources(List resources) throws RuperException {
for (Iterator iterator = resources.iterator(); iterator.hasNext();) {
downloadResource((Resource) iterator.next());
}
}
public void downloadResource(Resource resource) throws RuperException {
if (resource != null)
m_ruper.downloadResource(resource);
}
private List getFileNames(List resources) {
List fileNames = null;
for (Iterator iterator = resources.iterator(); iterator.hasNext();) {
Resource resource = (Resource) iterator.next();
if (resource != null)
fileNames.add(resource.getFilename());
}
return fileNames;
}
private List getResourceList(File file, boolean setTargetRepository)
throws RuperException {
List resourceList = null;
if (file != null) {
try {
switch (file.getType()) {
case IResource.FILE :
{
// get the resource from the file
Resource resource =
getResource(
file.getRawLocation().toFile(),
setTargetRepository);
if (resource != null) {
resourceList.add(resource);
}
}
break;
case IResource.FOLDER :
{
// get the files from the folder
java.io.File folder =
file.getRawLocation().toFile();
if (folder.isDirectory()) {
java.io.File[] stdFiles = folder.listFiles();
// convert the files to resources
for (int i = 0; i < stdFiles.length; i++) {
Resource resource =
getResource(
stdFiles[i],
setTargetRepository);
resourceList.add(resource);
}
}
}
break;
case IResource.PROJECT :
{
// get buildtime libraries for java project
ArrayList buildLibs =
m_ruperEclipseHelper.getBuildTimeLibraries(
file.getProject());
// convert to resources
if (buildLibs != null) {
for (Iterator iterator = buildLibs.iterator();
iterator.hasNext();
) {
String fileName = (String) iterator.next();
Resource resource =
getResource(
new java.io.File(fileName),
setTargetRepository);
if (resource != null) {
resourceList.add(resource);
}
}
}
}
break;
}
}
catch (Exception exp) {
throw new RuperException(exp);
}
}
else {
//TODO error message - file null
}
return resourceList;
}
private Resource getResource(
java.io.File file,
boolean setTargetRepository)
throws RuperException {
Resource resource = null;
try {
if (file != null) {
// get the absolute file path
String path = file.getCanonicalPath();
if (path != null) {
int baseIndex = path.lastIndexOf("/");
String base = path.substring(0, baseIndex);
String fileName = path.substring(baseIndex, path.length());
resource = getResource(base, fileName, true);
}
}
}
catch (Exception exp) {
// TODO message error
//exp.printStackTrace();
throw new RuperException(exp);
}
return resource;
}
private Resource getResource(
String base,
Object file,
boolean setTargetRepository)
throws RuperException {
Resource resource = null;
if (setTargetRepository) {
// get a repository with the baseDir
Repository targetRepository =
(Repository) Repository.getRepository(base, true);
targetRepository.setVirtualResourceLocator(
new VirtualResourceLocator(base));
// set it as the target repository
m_ruper.setDefaultTargetRepository(targetRepository);
}
// use file name analyzer to get the resource
if (base != null) {
m_fileNameAnalyzer.setBase(new VirtualResourceLocator(base));
resource = m_fileNameAnalyzer.determineResource(file);
}
else {
if (file instanceof String) {
resource =
m_fileNameAnalyzer.determineResource(
new VirtualResourceLocator((String) file));
}
else
resource = m_fileNameAnalyzer.determineResource(file);
}
return resource;
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.