blob: 255238601dc83bd10430de0c34b69902f67dfc35 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*******************************************************************************
* Copyright (c) 2007 Alphonse Van Assche.
* 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:
* Alphonse Van Assche - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpmstubby;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.linuxtools.internal.rpmstubby.model.MainPackage;
import org.eclipse.linuxtools.internal.rpmstubby.model.SubPackage;
/**
* Utility class used for writing the generated specfile to a file.
*
*/
public class SpecfileWriter {
IPreferenceStore store;
/**
* Creates the writer.
*/
public SpecfileWriter() {
store = StubbyPlugin.getDefault().getPreferenceStore();
}
/**
* Parse the feature.xml and write the generated specfile.
* @param featureFile The feature.xml file.
*/
public void write(IFile featureFile) {
// Populate Main package model
StubbyPackageModel stubbyPackageModel = new StubbyPackageModel(
featureFile);
MainPackage mainPackage = new MainPackage();
stubbyPackageModel.populatePackageData(mainPackage);
stubbyPackageModel.populatePackagePreambleData(mainPackage);
stubbyPackageModel.populateDocFiles(mainPackage);
List<IFile> includedFeatureFiles = stubbyPackageModel.getIncudedFeatures();
// Populate Sub package model
List<SubPackage> subPackages = new ArrayList<SubPackage>();
for (IFile includedFeatureFile: includedFeatureFiles) {
StubbyPackageModel strubbySubPackageModel = new StubbyPackageModel(
includedFeatureFile);
SubPackage subPackage = new SubPackage();
strubbySubPackageModel.populatePackageData(subPackage);
subPackages.add(subPackage);
}
if (!stubbyPackageModel.isAllIncludedFeatureFound()) {
String message = "";
if (stubbyPackageModel.getMissingFeaturesAsString().indexOf(",") >= 0) {
message = "Stub out an RPM specfile for '"
+ mainPackage.getName()
+ "' fails because '"
+ stubbyPackageModel.getMissingFeaturesAsString()
+ "' features were not found.\n\n"
+ "Please, add these features somewhere in your workspace.\n";
} else {
message = "Stub out an RPM specfile for '"
+ mainPackage.getName()
+ "' fails because '"
+ stubbyPackageModel.getMissingFeaturesAsString()
+ "' feature was not found.\n\n"
+ "Please, add these feature somewhere in your workspace.\n";
}
MessageDialog.openError(StubbyPlugin.getActiveWorkbenchShell(),
null, message);
} else {
// Write generated files to the main feature project
StubbyGenerator generator = new StubbyGenerator(mainPackage,
subPackages);
String packageName = "eclipse-"
+ generator.getPackageName(mainPackage.getName());
try {
generator.writeContent(featureFile.getProject().getName(), packageName.toLowerCase() + ".spec", generator.generateSpecfile());
} catch (CoreException e) {
StubbyLog.logError(e);
}
}
}
}
|