Commit cc02dcc4 authored by Johannes Eder's avatar Johannes Eder
Browse files

added file import check+copy

refs 1007
parent 1d8fb1c9
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.project.utils;
import java.io.File;
import java.io.IOException;
import org.conqat.lib.commons.filesystem.FileSystemUtils;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.model.IExternalDocumentReference;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
/**
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ExternalFileUtils {
/**
* Check given e-object and all its children for {@link IExternalDocumentReference}
*
*/
public static void checkImportedFileReferences(FileProject fileProject, URI sourceFileURI,
URI targetFileURI) {
TreeIterator<EObject> currentContents = fileProject.eAllContents();
while(currentContents.hasNext()) {
EObject current = currentContents.next();
if(current instanceof IExternalDocumentReference) {
IExternalDocumentReference ref = (IExternalDocumentReference)current;
File sourcePath = new File(sourceFileURI.path()).getParentFile().getAbsoluteFile();
File destinationPath =
new File(targetFileURI.path()).getParentFile().getAbsoluteFile();
File sourceFile = new File(sourcePath, ref.getUri());
if(!sourceFile.exists()) {
LoggingUtils.warning(ToolingKernelActivator.getDefault(), "Could not load " +
ref.getUri());
continue;
}
// check file type
try {
FileSystemUtils.copyFile(sourceFile, new File(destinationPath, ref.getUri()));
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment