Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "desktopdllapi.h"
31 : : #include "dp_misc.h"
32 : : #include "unopkg_main.h"
33 : : #include "unopkg_shared.h"
34 : : #include "dp_identifier.hxx"
35 : : #include "tools/extendapplicationenvironment.hxx"
36 : : #include "rtl/ustrbuf.hxx"
37 : : #include "rtl/uri.hxx"
38 : : #include "rtl/bootstrap.hxx"
39 : : #include "osl/thread.h"
40 : : #include "osl/process.h"
41 : : #include "osl/conditn.hxx"
42 : : #include "osl/file.hxx"
43 : : #include "cppuhelper/implbase1.hxx"
44 : : #include "cppuhelper/exc_hlp.hxx"
45 : : #include "comphelper/anytostring.hxx"
46 : : #include "comphelper/sequence.hxx"
47 : : #include "com/sun/star/deployment/ExtensionManager.hpp"
48 : :
49 : : #include "com/sun/star/deployment/ui/PackageManagerDialog.hpp"
50 : : #include "com/sun/star/ui/dialogs/XExecutableDialog.hpp"
51 : : #include "com/sun/star/lang/DisposedException.hpp"
52 : : #include "boost/scoped_array.hpp"
53 : : #include "com/sun/star/ui/dialogs/XDialogClosedListener.hpp"
54 : : #include "com/sun/star/bridge/XBridgeFactory.hpp"
55 : : #include <stdio.h>
56 : : #include <vector>
57 : :
58 : :
59 : : using namespace ::com::sun::star;
60 : : using namespace ::com::sun::star::uno;
61 : : using namespace ::unopkg;
62 : : using ::rtl::OUString;
63 : : namespace css = ::com::sun::star;
64 : : namespace {
65 : :
66 : 0 : struct ExtensionName
67 : : {
68 : : OUString m_str;
69 : 0 : ExtensionName( OUString const & str ) : m_str( str ) {}
70 : 0 : bool operator () ( Reference<deployment::XPackage> const & e ) const
71 : : {
72 : 0 : if (m_str.equals(dp_misc::getIdentifier(e))
73 : 0 : || m_str.equals(e->getName()))
74 : 0 : return true;
75 : 0 : return false;
76 : : }
77 : : };
78 : :
79 : : //------------------------------------------------------------------------------
80 : : const char s_usingText [] =
81 : : "\n"
82 : : "using: " APP_NAME " add <options> extension-path...\n"
83 : : " " APP_NAME " validate <options> extension-identifier...\n"
84 : : " " APP_NAME " remove <options> extension-identifier...\n"
85 : : " " APP_NAME " list <options> extension-identifier...\n"
86 : : " " APP_NAME " reinstall <options>\n"
87 : : " " APP_NAME " gui\n"
88 : : " " APP_NAME " -V\n"
89 : : " " APP_NAME " -h\n"
90 : : "\n"
91 : : "sub-commands:\n"
92 : : " add add extension\n"
93 : : " validate checks the prerequisites of an installed extension and"
94 : : " registers it if possible\n"
95 : : " remove remove extensions by identifier\n"
96 : : " reinstall expert feature: reinstall all deployed extensions\n"
97 : : " list list information about deployed extensions\n"
98 : : " gui raise Extension Manager Graphical User Interface (GUI)\n"
99 : : "\n"
100 : : "options:\n"
101 : : " -h, --help this help\n"
102 : : " -V, --version version information\n"
103 : : " -v, --verbose verbose output to stdout\n"
104 : : " -f, --force force overwriting existing extensions\n"
105 : : " -s, --suppress-license prevents showing the license\n"
106 : : " --log-file <file> custom log file; default: <cache-dir>/log.txt\n"
107 : : " --shared expert feature: operate on shared installation\n"
108 : : " deployment context;\n"
109 : : " run only when no concurrent Office\n"
110 : : " process(es) are running!\n"
111 : : " --bundled expert feature: operate on bundled extensions. Only\n"
112 : : " works with list, validate, reinstall;\n"
113 : : " --deployment-context expert feature: explicit deployment context\n"
114 : : " <context>\n"
115 : : "\n"
116 : : "To learn more about the Extension Manager and extensions, see:\n"
117 : : "http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Extensions/Extensions\n\n";
118 : :
119 : : //------------------------------------------------------------------------------
120 : : const OptionInfo s_option_infos [] = {
121 : : { RTL_CONSTASCII_STRINGPARAM("help"), 'h', false },
122 : : { RTL_CONSTASCII_STRINGPARAM("version"), 'V', false },
123 : : { RTL_CONSTASCII_STRINGPARAM("verbose"), 'v', false },
124 : : { RTL_CONSTASCII_STRINGPARAM("force"), 'f', false },
125 : : { RTL_CONSTASCII_STRINGPARAM("log-file"), '\0', true },
126 : : { RTL_CONSTASCII_STRINGPARAM("shared"), '\0', false },
127 : : { RTL_CONSTASCII_STRINGPARAM("deployment-context"), '\0', true },
128 : : { RTL_CONSTASCII_STRINGPARAM("bundled"), '\0', false},
129 : : { RTL_CONSTASCII_STRINGPARAM("suppress-license"), 's', false},
130 : :
131 : : { 0, 0, '\0', false }
132 : : };
133 : :
134 : 0 : class DialogClosedListenerImpl :
135 : : public ::cppu::WeakImplHelper1< ui::dialogs::XDialogClosedListener >
136 : : {
137 : : osl::Condition & m_rDialogClosedCondition;
138 : :
139 : : public:
140 : 0 : DialogClosedListenerImpl( osl::Condition & rDialogClosedCondition )
141 : 0 : : m_rDialogClosedCondition( rDialogClosedCondition ) {}
142 : :
143 : : // XEventListener (base of XDialogClosedListener)
144 : : virtual void SAL_CALL disposing( lang::EventObject const & Source )
145 : : throw (RuntimeException);
146 : :
147 : : // XDialogClosedListener
148 : : virtual void SAL_CALL dialogClosed(
149 : : ui::dialogs::DialogClosedEvent const & aEvent )
150 : : throw (RuntimeException);
151 : : };
152 : :
153 : : // XEventListener (base of XDialogClosedListener)
154 : 0 : void DialogClosedListenerImpl::disposing( lang::EventObject const & )
155 : : throw (RuntimeException)
156 : : {
157 : : // nothing to do
158 : 0 : }
159 : :
160 : : // XDialogClosedListener
161 : 0 : void DialogClosedListenerImpl::dialogClosed(
162 : : ui::dialogs::DialogClosedEvent const & )
163 : : throw (RuntimeException)
164 : : {
165 : 0 : m_rDialogClosedCondition.set();
166 : 0 : }
167 : :
168 : : // If a package had been installed with a pre OOo 2.2, it could not normally be
169 : : // found via its identifier; similarly (and for ease of use), a package
170 : : // installed with OOo 2.2 or later could not normally be found via its file
171 : : // name.
172 : 0 : Reference<deployment::XPackage> findPackage(
173 : : OUString const & repository,
174 : : Reference<deployment::XExtensionManager> const & manager,
175 : : Reference<ucb::XCommandEnvironment > const & environment,
176 : : OUString const & idOrFileName )
177 : : {
178 : : Sequence< Reference<deployment::XPackage> > ps(
179 : 0 : manager->getDeployedExtensions(repository,
180 : 0 : Reference<task::XAbortChannel>(), environment ) );
181 : 0 : for ( sal_Int32 i = 0; i < ps.getLength(); ++i )
182 : 0 : if ( dp_misc::getIdentifier( ps[i] ) == idOrFileName )
183 : 0 : return ps[i];
184 : 0 : for ( sal_Int32 i = 0; i < ps.getLength(); ++i )
185 : 0 : if ( ps[i]->getName() == idOrFileName )
186 : 0 : return ps[i];
187 : 0 : return Reference<deployment::XPackage>();
188 : : }
189 : :
190 : : } // anon namespace
191 : :
192 : :
193 : : //workaround for some reason the bridge threads which communicate with the uno.exe
194 : : //process are not releases on time
195 : 0 : void disposeBridges(Reference<css::uno::XComponentContext> ctx)
196 : : {
197 : 0 : if (!ctx.is())
198 : 0 : return;
199 : :
200 : : Reference<css::bridge::XBridgeFactory> bridgeFac(
201 : 0 : ctx->getServiceManager()->createInstanceWithContext(
202 : 0 : OUSTR("com.sun.star.bridge.BridgeFactory"), ctx),
203 : 0 : UNO_QUERY);
204 : :
205 : 0 : if (bridgeFac.is())
206 : : {
207 : 0 : const Sequence< Reference<css::bridge::XBridge> >seqBridges = bridgeFac->getExistingBridges();
208 : 0 : for (sal_Int32 i = 0; i < seqBridges.getLength(); i++)
209 : : {
210 : 0 : Reference<css::lang::XComponent> comp(seqBridges[i], UNO_QUERY);
211 : 0 : if (comp.is())
212 : : {
213 : : try {
214 : 0 : comp->dispose();
215 : : }
216 : 0 : catch ( const css::lang::DisposedException& )
217 : : {
218 : : }
219 : : }
220 : 0 : }
221 : 0 : }
222 : : }
223 : :
224 : 0 : extern "C" DESKTOP_DLLPUBLIC int unopkg_main()
225 : : {
226 : 0 : tools::extendApplicationEnvironment();
227 : 0 : DisposeGuard disposeGuard;
228 : 0 : bool bNoOtherErrorMsg = false;
229 : 0 : OUString subCommand;
230 : 0 : bool option_shared = false;
231 : 0 : bool option_force = false;
232 : 0 : bool option_verbose = false;
233 : 0 : bool option_bundled = false;
234 : 0 : bool option_suppressLicense = false;
235 : 0 : bool subcmd_add = false;
236 : 0 : bool subcmd_gui = false;
237 : 0 : OUString logFile;
238 : 0 : OUString repository;
239 : 0 : OUString cmdArg;
240 : 0 : ::std::vector<OUString> cmdPackages;
241 : :
242 : : OptionInfo const * info_shared = getOptionInfo(
243 : 0 : s_option_infos, OUSTR("shared") );
244 : : OptionInfo const * info_force = getOptionInfo(
245 : 0 : s_option_infos, OUSTR("force") );
246 : : OptionInfo const * info_verbose = getOptionInfo(
247 : 0 : s_option_infos, OUSTR("verbose") );
248 : : OptionInfo const * info_log = getOptionInfo(
249 : 0 : s_option_infos, OUSTR("log-file") );
250 : : OptionInfo const * info_context = getOptionInfo(
251 : 0 : s_option_infos, OUSTR("deployment-context") );
252 : : OptionInfo const * info_help = getOptionInfo(
253 : 0 : s_option_infos, OUSTR("help") );
254 : : OptionInfo const * info_version = getOptionInfo(
255 : 0 : s_option_infos, OUSTR("version") );
256 : : OptionInfo const * info_bundled = getOptionInfo(
257 : 0 : s_option_infos, OUSTR("bundled") );
258 : : OptionInfo const * info_suppressLicense = getOptionInfo(
259 : 0 : s_option_infos, OUSTR("suppress-license") );
260 : :
261 : :
262 : 0 : Reference<XComponentContext> xComponentContext;
263 : 0 : Reference<XComponentContext> xLocalComponentContext;
264 : :
265 : : try {
266 : 0 : sal_uInt32 nPos = 0;
267 : 0 : sal_uInt32 nCount = osl_getCommandArgCount();
268 : 0 : if (nCount == 0 || isOption( info_help, &nPos ))
269 : : {
270 : 0 : dp_misc::writeConsole(s_usingText);
271 : 0 : return 0;
272 : : }
273 : 0 : else if (isOption( info_version, &nPos )) {
274 : 0 : dp_misc::writeConsole("\n" APP_NAME " Version 3.3\n");
275 : 0 : return 0;
276 : : }
277 : : //consume all bootstrap variables which may occur before the subcommannd
278 : 0 : while(isBootstrapVariable(&nPos))
279 : : ;
280 : :
281 : 0 : if(nPos >= nCount)
282 : 0 : return 0;
283 : : //get the sub command
284 : 0 : osl_getCommandArg( nPos, &subCommand.pData );
285 : 0 : ++nPos;
286 : 0 : subCommand = subCommand.trim();
287 : 0 : subcmd_add = subCommand == "add";
288 : 0 : subcmd_gui = subCommand == "gui";
289 : :
290 : : // sun-command options and packages:
291 : 0 : while (nPos < nCount)
292 : : {
293 : 0 : if (readArgument( &cmdArg, info_log, &nPos )) {
294 : : logFile = makeAbsoluteFileUrl(
295 : 0 : cmdArg.trim(), getProcessWorkingDir() );
296 : : }
297 : 0 : else if (!readOption( &option_verbose, info_verbose, &nPos ) &&
298 : 0 : !readOption( &option_shared, info_shared, &nPos ) &&
299 : 0 : !readOption( &option_force, info_force, &nPos ) &&
300 : 0 : !readOption( &option_bundled, info_bundled, &nPos ) &&
301 : 0 : !readOption( &option_suppressLicense, info_suppressLicense, &nPos ) &&
302 : 0 : !readArgument( &repository, info_context, &nPos ) &&
303 : 0 : !isBootstrapVariable(&nPos))
304 : : {
305 : 0 : osl_getCommandArg( nPos, &cmdArg.pData );
306 : 0 : ++nPos;
307 : 0 : cmdArg = cmdArg.trim();
308 : 0 : if (!cmdArg.isEmpty())
309 : : {
310 : 0 : if (cmdArg[ 0 ] == '-')
311 : : {
312 : : // is option:
313 : : dp_misc::writeConsoleError(
314 : : OUSTR("\nERROR: unexpected option ") +
315 : : cmdArg +
316 : : OUSTR("!\n") +
317 : : OUSTR(" Use " APP_NAME " ") +
318 : : toString(info_help) +
319 : 0 : OUSTR(" to print all options.\n"));
320 : 0 : return 1;
321 : : }
322 : : else
323 : : {
324 : : // is package:
325 : : cmdPackages.push_back(
326 : : subcmd_add || subcmd_gui
327 : : ? makeAbsoluteFileUrl(
328 : 0 : cmdArg, getProcessWorkingDir() )
329 : 0 : : cmdArg );
330 : : }
331 : : }
332 : : }
333 : : }
334 : :
335 : 0 : if (repository.isEmpty())
336 : : {
337 : 0 : if (option_shared)
338 : 0 : repository = OUSTR("shared");
339 : 0 : else if (option_bundled)
340 : 0 : repository = OUSTR("bundled");
341 : : else
342 : 0 : repository = OUSTR("user");
343 : : }
344 : : else
345 : : {
346 : 0 : if ( repository == "shared" ) {
347 : 0 : option_shared = true;
348 : : }
349 : 0 : else if (option_shared) {
350 : : dp_misc::writeConsoleError(
351 : : OUSTR("WARNING: explicit context given! ") +
352 : : OUSTR("Ignoring option ") +
353 : : toString( info_shared ) +
354 : 0 : OUSTR("!\n") );
355 : : }
356 : : }
357 : :
358 : 0 : if (subCommand.equals(OUSTR("reinstall")))
359 : : {
360 : : //We must prevent that services and types are loaded by UNO,
361 : : //otherwise we cannot delete the registry data folder.
362 : 0 : OUString extensionUnorc;
363 : 0 : if (repository.equals(OUSTR("user")))
364 : 0 : extensionUnorc = OUSTR("$UNO_USER_PACKAGES_CACHE/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc");
365 : 0 : else if (repository.equals(OUSTR("shared")))
366 : 0 : extensionUnorc = OUSTR("$SHARED_EXTENSIONS_USER/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc");
367 : 0 : else if (repository.equals(OUSTR("bundled")))
368 : 0 : extensionUnorc = OUSTR("$BUNDLED_EXTENSIONS_USER/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc");
369 : : else
370 : : OSL_ASSERT(0);
371 : :
372 : 0 : ::rtl::Bootstrap::expandMacros(extensionUnorc);
373 : 0 : oslFileError e = osl_removeFile(extensionUnorc.pData);
374 : 0 : if (e != osl_File_E_None && e != osl_File_E_NOENT)
375 : 0 : throw Exception(OUSTR("Could not delete ") + extensionUnorc, 0);
376 : : }
377 : :
378 : : xComponentContext = getUNO(
379 : : disposeGuard, option_verbose, option_shared, subcmd_gui,
380 : 0 : xLocalComponentContext );
381 : :
382 : : Reference<deployment::XExtensionManager> xExtensionManager(
383 : 0 : deployment::ExtensionManager::get( xComponentContext ) );
384 : :
385 : : Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv(
386 : : createCmdEnv( xComponentContext, logFile,
387 : 0 : option_force, option_verbose, option_suppressLicense) );
388 : :
389 : : //synchronize bundled/shared extensions
390 : : //Do not synchronize when command is "reinstall". This could add types and services to UNO and
391 : : //prevent the deletion of the registry data folder
392 : : //synching is done in XExtensionManager.reinstall
393 : 0 : if (!subcmd_gui && ! subCommand.equals(OUSTR("reinstall"))
394 : 0 : && ! dp_misc::office_is_running())
395 : 0 : dp_misc::syncRepositories(xCmdEnv);
396 : :
397 : 0 : if ( subcmd_add || subCommand == "remove" )
398 : : {
399 : 0 : for ( ::std::size_t pos = 0; pos < cmdPackages.size(); ++pos )
400 : : {
401 : 0 : OUString const & cmdPackage = cmdPackages[ pos ];
402 : 0 : if (subcmd_add)
403 : : {
404 : : beans::NamedValue nvSuppress(
405 : : OUSTR("SUPPRESS_LICENSE"), option_suppressLicense ?
406 : 0 : makeAny(OUSTR("1")):makeAny(OUSTR("0")));
407 : 0 : xExtensionManager->addExtension(
408 : : cmdPackage, Sequence<beans::NamedValue>(&nvSuppress, 1),
409 : 0 : repository, Reference<task::XAbortChannel>(), xCmdEnv);
410 : : }
411 : : else
412 : : {
413 : : try
414 : : {
415 : 0 : xExtensionManager->removeExtension(
416 : : cmdPackage, cmdPackage, repository,
417 : 0 : Reference<task::XAbortChannel>(), xCmdEnv );
418 : : }
419 : 0 : catch (const lang::IllegalArgumentException &)
420 : : {
421 : : Reference<deployment::XPackage> p(
422 : : findPackage(repository,
423 : 0 : xExtensionManager, xCmdEnv, cmdPackage ) );
424 : 0 : if ( !p.is())
425 : 0 : throw;
426 : 0 : else if (p.is())
427 : 0 : xExtensionManager->removeExtension(
428 : 0 : ::dp_misc::getIdentifier(p), p->getName(),
429 : : repository,
430 : 0 : Reference<task::XAbortChannel>(), xCmdEnv );
431 : : }
432 : : }
433 : : }
434 : : }
435 : 0 : else if (subCommand.equalsAsciiL(
436 : 0 : RTL_CONSTASCII_STRINGPARAM("reinstall") ))
437 : : {
438 : 0 : xExtensionManager->reinstallDeployedExtensions(
439 : 0 : repository, Reference<task::XAbortChannel>(), xCmdEnv);
440 : : }
441 : 0 : else if ( subCommand == "list" )
442 : : {
443 : 0 : ::std::vector<Reference<deployment::XPackage> > vecExtUnaccepted;
444 : : ::comphelper::sequenceToContainer(vecExtUnaccepted,
445 : 0 : xExtensionManager->getExtensionsWithUnacceptedLicenses(
446 : 0 : repository, xCmdEnv));
447 : :
448 : : //This vector tells what XPackage in allExtensions has an
449 : : //unaccepted license.
450 : 0 : std::vector<bool> vecUnaccepted;
451 : 0 : std::vector<Reference<deployment::XPackage> > allExtensions;
452 : 0 : if (cmdPackages.empty())
453 : : {
454 : : Sequence< Reference<deployment::XPackage> >
455 : 0 : packages = xExtensionManager->getDeployedExtensions(
456 : 0 : repository, Reference<task::XAbortChannel>(), xCmdEnv );
457 : :
458 : 0 : ::std::vector<Reference<deployment::XPackage> > vec_packages;
459 : 0 : ::comphelper::sequenceToContainer(vec_packages, packages);
460 : :
461 : : //First copy the extensions with the unaccepted license
462 : : //to vector allExtensions.
463 : 0 : allExtensions.resize(vecExtUnaccepted.size() + vec_packages.size());
464 : :
465 : : ::std::vector<Reference<deployment::XPackage> >::iterator i_all_ext =
466 : : ::std::copy(vecExtUnaccepted.begin(), vecExtUnaccepted.end(),
467 : 0 : allExtensions.begin());
468 : : //Now copy those we got from getDeployedExtensions
469 : 0 : ::std::copy(vec_packages.begin(), vec_packages.end(), i_all_ext);
470 : :
471 : : //Now prepare the vector which tells what extension has an
472 : : //unaccepted license
473 : 0 : vecUnaccepted.resize(vecExtUnaccepted.size() + vec_packages.size());
474 : 0 : ::std::fill_n(vecUnaccepted.begin(), vecExtUnaccepted.size(), true);
475 : 0 : ::std::fill_n(vecUnaccepted.begin() + vecExtUnaccepted.size(),
476 : 0 : vec_packages.size(), false);
477 : :
478 : : dp_misc::writeConsole(
479 : 0 : OUSTR("All deployed ") + repository + OUSTR(" extensions:\n\n"));
480 : : }
481 : : else
482 : : {
483 : : //The user provided the names (ids or file names) of the extensions
484 : : //which shall be listed
485 : 0 : for ( ::std::size_t pos = 0; pos < cmdPackages.size(); ++pos )
486 : : {
487 : 0 : Reference<deployment::XPackage> extension;
488 : : try
489 : : {
490 : 0 : extension = xExtensionManager->getDeployedExtension(
491 : 0 : repository, cmdPackages[ pos ], cmdPackages[ pos ], xCmdEnv );
492 : : }
493 : 0 : catch (const lang::IllegalArgumentException &)
494 : : {
495 : : extension = findPackage(repository,
496 : 0 : xExtensionManager, xCmdEnv, cmdPackages[ pos ] );
497 : : }
498 : :
499 : : //Now look if the requested extension has an unaccepted license
500 : 0 : bool bUnacceptedLic = false;
501 : 0 : if (!extension.is())
502 : : {
503 : : ::std::vector<Reference<deployment::XPackage> >::const_iterator
504 : : i = ::std::find_if(
505 : : vecExtUnaccepted.begin(),
506 : 0 : vecExtUnaccepted.end(), ExtensionName(cmdPackages[pos]));
507 : 0 : if (i != vecExtUnaccepted.end())
508 : : {
509 : 0 : extension = *i;
510 : 0 : bUnacceptedLic = true;
511 : : }
512 : : }
513 : :
514 : 0 : if (extension.is())
515 : : {
516 : 0 : allExtensions.push_back(extension);
517 : 0 : vecUnaccepted.push_back(bUnacceptedLic);
518 : : }
519 : :
520 : : else
521 : : throw lang::IllegalArgumentException(
522 : : OUSTR("There is no such extension deployed: ") +
523 : 0 : cmdPackages[pos],0,-1);
524 : 0 : }
525 : :
526 : : }
527 : :
528 : 0 : printf_packages(allExtensions, vecUnaccepted, xCmdEnv );
529 : : }
530 : 0 : else if ( subCommand == "validate" )
531 : : {
532 : 0 : ::std::vector<Reference<deployment::XPackage> > vecExtUnaccepted;
533 : : ::comphelper::sequenceToContainer(
534 : 0 : vecExtUnaccepted, xExtensionManager->getExtensionsWithUnacceptedLicenses(
535 : 0 : repository, xCmdEnv));
536 : :
537 : 0 : for ( ::std::size_t pos = 0; pos < cmdPackages.size(); ++pos )
538 : : {
539 : 0 : Reference<deployment::XPackage> extension;
540 : : try
541 : : {
542 : 0 : extension = xExtensionManager->getDeployedExtension(
543 : 0 : repository, cmdPackages[ pos ], cmdPackages[ pos ], xCmdEnv );
544 : : }
545 : 0 : catch (const lang::IllegalArgumentException &)
546 : : {
547 : : extension = findPackage(
548 : 0 : repository, xExtensionManager, xCmdEnv, cmdPackages[ pos ] );
549 : : }
550 : :
551 : 0 : if (!extension.is())
552 : : {
553 : : ::std::vector<Reference<deployment::XPackage> >::const_iterator
554 : : i = ::std::find_if(
555 : : vecExtUnaccepted.begin(),
556 : 0 : vecExtUnaccepted.end(), ExtensionName(cmdPackages[pos]));
557 : 0 : if (i != vecExtUnaccepted.end())
558 : : {
559 : 0 : extension = *i;
560 : : }
561 : : }
562 : :
563 : 0 : if (extension.is())
564 : 0 : xExtensionManager->checkPrerequisitesAndEnable(
565 : 0 : extension, Reference<task::XAbortChannel>(), xCmdEnv);
566 : 0 : }
567 : : }
568 : 0 : else if ( subCommand == "gui" )
569 : : {
570 : : Reference<ui::dialogs::XAsynchronousExecutableDialog> xDialog(
571 : : deployment::ui::PackageManagerDialog::createAndInstall(
572 : : xComponentContext,
573 : 0 : cmdPackages.size() > 0 ? cmdPackages[0] : OUString() ));
574 : :
575 : 0 : osl::Condition dialogEnded;
576 : 0 : dialogEnded.reset();
577 : :
578 : : Reference< ui::dialogs::XDialogClosedListener > xListener(
579 : 0 : new DialogClosedListenerImpl( dialogEnded ) );
580 : :
581 : 0 : xDialog->startExecuteModal(xListener);
582 : 0 : dialogEnded.wait();
583 : : }
584 : : else
585 : : {
586 : : dp_misc::writeConsoleError(
587 : : OUSTR("\nERROR: unknown sub-command ") +
588 : : subCommand +
589 : : OUSTR("!\n") +
590 : : OUSTR(" Use " APP_NAME " ") +
591 : : toString(info_help) +
592 : 0 : OUSTR(" to print all options.\n"));
593 : 0 : return 1;
594 : : }
595 : :
596 : 0 : if (option_verbose)
597 : 0 : dp_misc::writeConsole(OUSTR("\n" APP_NAME " done.\n"));
598 : : //Force to release all bridges which connect us to the child processes
599 : 0 : disposeBridges(xLocalComponentContext);
600 : 0 : return 0;
601 : : }
602 : 0 : catch (const ucb::CommandFailedException &e)
603 : : {
604 : 0 : dp_misc::writeConsoleError(e.Message + OUSTR("\n"));
605 : 0 : bNoOtherErrorMsg = true;
606 : : }
607 : 0 : catch (const ucb::CommandAbortedException &)
608 : : {
609 : 0 : dp_misc::writeConsoleError("\n" APP_NAME " aborted!\n");
610 : : }
611 : 0 : catch (const deployment::DeploymentException & exc)
612 : : {
613 : 0 : OUString cause;
614 : 0 : if (option_verbose)
615 : : {
616 : 0 : cause = ::comphelper::anyToString(exc.Cause);
617 : : }
618 : : else
619 : : {
620 : 0 : css::uno::Exception e;
621 : 0 : if (exc.Cause >>= e)
622 : 0 : cause = e.Message;
623 : : }
624 : :
625 : : dp_misc::writeConsoleError(
626 : 0 : OUSTR("\nERROR: ") + exc.Message + OUSTR("\n"));
627 : 0 : if (!cause.isEmpty())
628 : : dp_misc::writeConsoleError(
629 : 0 : OUSTR(" Cause: ") + cause + OUSTR("\n"));
630 : : }
631 : 0 : catch (const LockFileException & e)
632 : : {
633 : 0 : if (!subcmd_gui)
634 : 0 : dp_misc::writeConsoleError(e.Message);
635 : 0 : bNoOtherErrorMsg = true;
636 : : }
637 : 0 : catch (const ::com::sun::star::uno::Exception & e ) {
638 : 0 : Any exc( ::cppu::getCaughtException() );
639 : :
640 : : dp_misc::writeConsoleError(
641 : : OUSTR("\nERROR: ") +
642 : : OUString(option_verbose ? e.Message + OUSTR("\nException details: \n") +
643 : : ::comphelper::anyToString(exc) : e.Message) +
644 : 0 : OUSTR("\n"));
645 : : }
646 : 0 : if (!bNoOtherErrorMsg)
647 : 0 : dp_misc::writeConsoleError("\n" APP_NAME " failed.\n");
648 : 0 : disposeBridges(xLocalComponentContext);
649 : 0 : return 1;
650 : : }
651 : :
652 : :
653 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|