Skip to content

Commit

Permalink
Changes for v1.3 - Fix Guava issue on IntelliJ IDEA 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wimsymons committed Dec 10, 2014
1 parent e0dbf18 commit 2be4b24
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 64 deletions.
47 changes: 25 additions & 22 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<idea-plugin version="2" url="https://github.com/wimsymons/intellij-ppimport">
<id>be.wimsymons.intellij.polopolyimport</id>
<name>Polopoly Importer</name>
<version>1.2</version>
<vendor email="[email protected]">Wim Symons</vendor>
<id>be.wimsymons.intellij.polopolyimport</id>
<name>Polopoly Importer</name>
<version>1.3</version>
<vendor email="[email protected]">Wim Symons</vendor>

<description><![CDATA[
<description><![CDATA[
<p>
Plugin to import content XML into the Atex Polopoly CMS.
</p>
Expand All @@ -13,8 +13,11 @@ This version keeps state on application-level, not on project level.
</p>
]]></description>

<change-notes><![CDATA[
<change-notes><![CDATA[
<dl>
<dt>1.3</dt>
<dd>Fixed issue with Guava deprecating Closeables.closeQuietly in Guava 15</dd>
<dt>1.2</dt>
<dd>Fixed ArrayIndexOutOfBoundsException: 0 when there are no replacements.</dd>
Expand Down Expand Up @@ -53,21 +56,21 @@ This version keeps state on application-level, not on project level.
</dl>
]]></change-notes>

<idea-version since-build="107.105"/>

<application-components>
<component>
<implementation-class>be.wimsymons.intellij.polopolyimport.PPImportPlugin</implementation-class>
</component>
</application-components>

<actions>
<group id="PolopolyImportPluginGroup" popup="true" text="Polopoly Import" description="Import content">
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
<add-to-group group-id="StructureViewPopupMenu" anchor="last"/>
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
<add-to-group group-id="ChangesViewPopupMenu" anchor="last"/>
</group>
</actions>
<idea-version since-build="107.105" />

<application-components>
<component>
<implementation-class>be.wimsymons.intellij.polopolyimport.PPImportPlugin</implementation-class>
</component>
</application-components>

<actions>
<group id="PolopolyImportPluginGroup" popup="true" text="Polopoly Import" description="Import content">
<add-to-group group-id="ProjectViewPopupMenu" anchor="last" />
<add-to-group group-id="StructureViewPopupMenu" anchor="last" />
<add-to-group group-id="EditorPopupMenu" anchor="last" />
<add-to-group group-id="ChangesViewPopupMenu" anchor="last" />
</group>
</actions>

</idea-plugin>
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This is different from Johan or Marc's plugin, which store this information sepa

## Change log

1.3 Fixed issue with Guava deprecating Closeables.closeQuietly in Guava 15
1.2 Fixed ArrayIndexOutOfBoundsException: 0 when there are no replacements.
1.1 Fixed configuration storage again.
1.0 First release on plugins.jetbrains.com
Expand All @@ -43,12 +44,12 @@ This is different from Johan or Marc's plugin, which store this information sepa

Requires IntelliJ IDEA 11 or later.

Download the **polopoly-import-1.2.jar** from the **distributable** folder.
Download the **polopoly-import-1.3.jar** from the **distributable** folder.

1. Start IntelliJ IDEA.
2. Open the plugin manager dialog (**Menu: File > Settings > Plugins**)
3. Click **Install plugin from disk** button to open the **Choose Plugin file** dialog.
4. Select the **polopoly-import-1.2.jar** file and click **OK** to close the dialog.
4. Select the **polopoly-import-1.3.jar** file and click **OK** to close the dialog.
5. Click **OK** to close the **Settings** dialog.
6. Restart IntelliJ IDEA.

Expand Down
Binary file removed distributable/polopoly-import-1.2.jar
Binary file not shown.
Binary file added distributable/polopoly-import-1.3.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions intellij-ppimport.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="sonarModuleSettings">
<option name="alternativeWorkingDirPath" value="" />
<option name="localAnalysisScripName" value="&lt;PROJECT&gt;" />
<option name="serverName" value="&lt;PROJECT&gt;" />
<option name="useAlternativeWorkingDir" value="false" />
<option name="workingDirSelection" value="&lt;MODULE&gt;" />
</component>
</module>

62 changes: 25 additions & 37 deletions src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.base.Strings;
import com.google.common.io.CharStreams;
import com.google.common.io.Closeables;
import com.google.common.io.Closer;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
Expand Down Expand Up @@ -50,8 +49,7 @@ class PPImporter {
private int totalCount = 0;
private int skippedCount = 0;

public PPImporter(final ProgressIndicator progressIndicator, final Target target, final List<String> includeExtensions,
final List<Replacement> replacements, final boolean makeJar) {
public PPImporter(final ProgressIndicator progressIndicator, final Target target, final List<String> includeExtensions, final List<Replacement> replacements, final boolean makeJar) {
this.progressIndicator = progressIndicator;
this.target = target;
this.includeExtensions = includeExtensions;
Expand Down Expand Up @@ -141,7 +139,6 @@ private void doImportMultiple(final VirtualFile[] virtualFiles) {
private byte[] makeJar(VirtualFile[] files) throws IOException {
JarOutputStream jarOS = null;
ByteArrayOutputStream byteOS = null;
Closer closer = Closer.create();
try {
progressIndicator.setIndeterminate(true);

Expand All @@ -156,8 +153,8 @@ private byte[] makeJar(VirtualFile[] files) throws IOException {

totalCount = filesToProcess.size();

byteOS = closer.register(new ByteArrayOutputStream());
jarOS = closer.register(new JarOutputStream(byteOS));
byteOS = new ByteArrayOutputStream();
jarOS = new JarOutputStream(byteOS);
int counter = 0;
for (VirtualFile file : filesToProcess) {
if (progressIndicator.isCanceled()) {
Expand All @@ -178,30 +175,29 @@ private byte[] makeJar(VirtualFile[] files) throws IOException {
jarOS.flush();
return progressIndicator.isCanceled() ? null : byteOS.toByteArray();
} finally {
closer.close();
Closeables.close(jarOS, true);
Closeables.close(byteOS, true);
}
}

private void addToJar(JarOutputStream jarOS, VirtualFile file) throws IOException {
Closer closer = Closer.create();
JarEntry entry = new JarEntry(file.getCanonicalPath());
entry.setTime(file.getTimeStamp());
jarOS.putNextEntry(entry);
Reader reader = wrapWithReplacements(file.getInputStream());
Writer writer = new OutputStreamWriter(jarOS);
try {
Reader reader = closer.register(wrapWithReplacements(file.getInputStream()));
Writer writer = closer.register(new OutputStreamWriter(jarOS));
CharStreams.copy(reader, writer);
} finally {
closer.close();
Closeables.close(reader, true);
Closeables.close(writer, true);
}
}

private void postData(final String name, final Reader reader, final String contentType, final String extraParams) throws IOException {
Writer writer = null;
LOGGER.info("Doing HTTP POST for " + name);
Closer closer = Closer.create();
try {
closer.register(reader);
URL httpURL = buildURL(target, extraParams);

HttpURLConnection httpConnection = (HttpURLConnection) httpURL.openConnection();
Expand All @@ -212,30 +208,24 @@ private void postData(final String name, final Reader reader, final String conte
httpConnection.setReadTimeout(60000);
httpConnection.connect();

writer = closer.register(new OutputStreamWriter(httpConnection.getOutputStream()));
writer = new OutputStreamWriter(httpConnection.getOutputStream());
CharStreams.copy(reader, writer);
writer.flush();

int responseCode = httpConnection.getResponseCode();
String responseMessage = httpConnection.getResponseMessage();
if (responseCode < 200 || responseCode >= 300) {
failureCount++;
PPImportPlugin.doNotify(
"Import of "
+ name
+ " failed: "
+ responseCode
+ " - "
+ responseMessage
+ "\nCheck the server log for more details.", NotificationType.ERROR);
PPImportPlugin.doNotify("Import of " + name + " failed: " + responseCode + " - " + responseMessage + "\nCheck the server log for more details.", NotificationType.ERROR);
} else {
successCount++;
}
} catch (IOException e) {
failureCount++;
PPImportPlugin.doNotify("Import of " + name + " failed: " + e.getMessage(), NotificationType.ERROR);
} finally {
closer.close();
Closeables.close(reader, true);
Closeables.close(writer, true);
}
}

Expand All @@ -253,13 +243,12 @@ private URL buildURL(Target target, String extraParams) throws MalformedURLExcep

@SuppressWarnings("UnsafeVfsRecursion")
private void recurseFiles(@NotNull VirtualFile virtualFile, @NotNull ContentIterator iterator) {
TreeSet<VirtualFile> sortedDeduplicatedFiles = new TreeSet<VirtualFile>(
new Comparator<VirtualFile>() {
@Override
public int compare(VirtualFile f1, VirtualFile f2) {
return f1.getName().compareTo(f2.getName());
}
});
TreeSet<VirtualFile> sortedDeduplicatedFiles = new TreeSet<VirtualFile>(new Comparator<VirtualFile>() {
@Override
public int compare(VirtualFile f1, VirtualFile f2) {
return f1.getName().compareTo(f2.getName());
}
});
if (virtualFile.isDirectory()) {
Collections.addAll(sortedDeduplicatedFiles, virtualFile.getChildren());
for (VirtualFile child : sortedDeduplicatedFiles) {
Expand All @@ -273,13 +262,12 @@ public int compare(VirtualFile f1, VirtualFile f2) {
private Collection<VirtualFile> getFileList(@NotNull VirtualFile dir) {
LOGGER.info("Getting file list ...");
final Collection<VirtualFile> result = new LinkedHashSet<VirtualFile>();
recurseFiles(
dir, new ContentIterator() {
@Override
public boolean processFile(VirtualFile virtualFile) {
return result.add(virtualFile);
}
});
recurseFiles(dir, new ContentIterator() {
@Override
public boolean processFile(VirtualFile virtualFile) {
return result.add(virtualFile);
}
});
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ private String doReplace(String originalString, List<Replacement> replacements)
CharStreams.copy(reader, writer);
actual = writer.toString();
} finally {
Closeables.closeQuietly(reader);
Closeables.closeQuietly(in);
Closeables.closeQuietly(writer);
Closeables.close(reader, true);
Closeables.close(in, true);
Closeables.close(writer, true);
}
return actual;
}
Expand Down

0 comments on commit 2be4b24

Please sign in to comment.